Ticket #5520: ordered-tests.patch

File ordered-tests.patch, 3.4 KB (added by Julian, 2 years ago)
  • doc/core/man/trial.1

    diff --git a/doc/core/man/trial.1 b/doc/core/man/trial.1
    index f01934d..1b89412 100644
    a b packages and files listed on the command line. 
    1313trial will take either filenames or fully qualified Python names as 
    1414arguments.  Thus `trial myproject/foo.py', `trial myproject.foo' and 
    1515`trial myproject.foo.SomeTestCase.test_method' are all valid ways to 
    16 invoke trial. 
     16invoke trial. Multiple such arguments are also accepted, and their order will 
     17determine the order in which the corresponding tests are run. 
    1718.PP 
    1819After running the given test suite, the default test reporter prints a summary 
    1920of the test run. This consists of the word "PASSED" (if all tests ran as 
  • twisted/scripts/trial.py

    diff --git a/twisted/scripts/trial.py b/twisted/scripts/trial.py
    index 349b0c6..e57a22f 100644
    a b  
    44# See LICENSE for details. 
    55 
    66 
    7 import sys, os, random, gc, time, warnings 
     7import sys, os, collections, random, gc, time, warnings 
    88 
    99from twisted.internet import defer 
    1010from twisted.application import app 
    def _reporterAction(): 
    9393    return usage.CompleteList([p.longOpt for p in 
    9494                               plugin.getPlugins(itrial.IReporter)]) 
    9595 
     96 
     97class _OrderedSet(collections.MutableSet): 
     98    def __init__(self, contents=()): 
     99        self._contents = collections.OrderedDict() 
     100        self.update(contents) 
     101 
     102    def __contains__(self, e): 
     103        return e in self._contents 
     104 
     105    def __iter__(self): 
     106        return iter(self._contents) 
     107 
     108    def __len__(self): 
     109        return len(self._contents) 
     110 
     111    def __repr__(self): 
     112        return "%s(%s)" % (self.__class__.__name__, list(self._contents)) 
     113 
     114    def add(self, e): 
     115        self._contents[e] = None 
     116 
     117    def discard(self, e): 
     118        if e in self._contents: 
     119            del self._contents[e] 
     120 
     121    def update(self, contents): 
     122        self._contents.update((e, None) for e in contents) 
     123 
     124 
    96125class Options(usage.Options, app.ReactorSelectionMixin): 
    97126    synopsis = """%s [options] [[file|package|module|TestCase|testmethod]...] 
    98127    """ % (os.path.basename(sys.argv[0]),) 
    class Options(usage.Options, app.ReactorSelectionMixin): 
    146175    tracer = None 
    147176 
    148177    def __init__(self): 
    149         self['tests'] = set() 
     178        self['tests'] = _OrderedSet() 
    150179        usage.Options.__init__(self) 
    151180 
    152181 
  • twisted/trial/test/test_script.py

    diff --git a/twisted/trial/test/test_script.py b/twisted/trial/test/test_script.py
    index 6c93ebe..bcae843 100644
    a b class ExtraTests(unittest.TestCase): 
    480480        self.assertDeprecationWarning(self.config.opt_extra, 
    481481                                      self.flushWarnings([self.test_xDeprecation])) 
    482482 
     483 
     484 
     485class TestArgumentOrderTests(unittest.TestCase): 
     486    def setUp(self): 
     487        self.config = trial.Options() 
     488        self.loader = runner.TestLoader() 
     489 
     490    def test_preserveArgumentOrder(self): 
     491        """ 
     492        Multiple tests passed on the command line should not be reordered. 
     493 
     494        """ 
     495 
     496        tests = ["foo", "bar", "quux", "baz"] 
     497        self.config.parseOptions(tests) 
     498 
     499        suite = trial._getSuite(self.config) 
     500        names = testNames(suite) 
     501 
     502        expected_suite = runner.TestSuite(map(self.loader.loadByName, tests)) 
     503        expected_names = testNames(expected_suite) 
     504 
     505        self.assertEqual(names, expected_names)