Ticket #5520: ordered-tests-loadByNames.patch

File ordered-tests-loadByNames.patch, 2.0 KB (added by Julian, 3 years ago)
  • twisted/trial/runner.py

    diff --git a/twisted/trial/runner.py b/twisted/trial/runner.py
    index 68663b5..a9a72ec 100644
    a b class TestLoader(object): 
    657657        to same value and collapse to one test unexpectedly if using simpler
    658658        means: e.g. set().
    659659        """
    660         entries = []
     660        seen = set()
    661661        for thing in things:
    662662            if isinstance(thing, types.MethodType):
    663                 entries.append((thing, thing.im_class))
     663                thing = (thing, thing.im_class)
    664664            else:
    665                 entries.append((thing,))
    666         return [entry[0] for entry in set(entries)]
     665                thing = (thing,)
     666
     667            if thing not in seen:
     668                yield thing[0]
     669                seen.add(thing)
    667670
    668671
    669672
  • twisted/trial/test/test_loader.py

    diff --git a/twisted/trial/test/test_loader.py b/twisted/trial/test/test_loader.py
    index f08588e..6dd37a7 100644
    a b class LoaderTest(packages.SysPathManglingTest): 
    477477        self.assertSuitesEqual(suite1, suite2)
    478478
    479479
     480    def test_loadByNamesPreservesOrder(self):
     481        """
     482        L{TestLoader.loadByNames} preserves the order of tests provided to it.
     483        """
     484        modules = [
     485            "goodpackage",
     486            "twisted.trial.test.test_test_visitor",
     487            "package.test_module"]
     488        suite1 = self.loader.loadByNames(modules)
     489        suite2 = runner.TestSuite(map(self.loader.loadByName, modules))
     490        self.assertEqual(testNames(suite1), testNames(suite2))
     491
     492        modules = [
     493            "twisted.trial.test.test_test_visitor",
     494            "goodpackage",
     495            "package.test_module"]
     496        suite1 = self.loader.loadByNames(modules)
     497        suite2 = runner.TestSuite(map(self.loader.loadByName, modules))
     498        self.assertEqual(testNames(suite1), testNames(suite2))
     499
     500
    480501    def test_loadDifferentNames(self):
    481502        """
    482503        Check that loadByNames loads all the names that it is given