mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Merge e274f3a1a0 into 7099af8f5e
This commit is contained in:
commit
bbdf454608
3 changed files with 14 additions and 3 deletions
|
|
@ -2426,15 +2426,24 @@ The third argument is used when loading packages as part of test discovery.
|
||||||
A typical ``load_tests`` function that loads tests from a specific set of
|
A typical ``load_tests`` function that loads tests from a specific set of
|
||||||
:class:`TestCase` classes may look like::
|
:class:`TestCase` classes may look like::
|
||||||
|
|
||||||
test_cases = (TestCase1, TestCase2, TestCase3)
|
|
||||||
|
|
||||||
def load_tests(loader, tests, pattern):
|
def load_tests(loader, tests, pattern):
|
||||||
suite = TestSuite()
|
suite = TestSuite()
|
||||||
for test_class in test_cases:
|
for test_class in make_testcase_classes():
|
||||||
tests = loader.loadTestsFromTestCase(test_class)
|
tests = loader.loadTestsFromTestCase(test_class)
|
||||||
suite.addTests(tests)
|
suite.addTests(tests)
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
|
This could be used to load a set of tests that are dynamically generated to
|
||||||
|
run against different backends, for example::
|
||||||
|
|
||||||
|
def make_testcase_classes():
|
||||||
|
for backend in backends:
|
||||||
|
yield type(
|
||||||
|
'{}Test'.format(backend.name),
|
||||||
|
(TheBaseClass, unittest.TestCase),
|
||||||
|
{'backend': backend}
|
||||||
|
)
|
||||||
|
|
||||||
If discovery is started in a directory containing a package, either from the
|
If discovery is started in a directory containing a package, either from the
|
||||||
command line or by calling :meth:`TestLoader.discover`, then the package
|
command line or by calling :meth:`TestLoader.discover`, then the package
|
||||||
:file:`__init__.py` will be checked for ``load_tests``. If that function does
|
:file:`__init__.py` will be checked for ``load_tests``. If that function does
|
||||||
|
|
|
||||||
|
|
@ -963,6 +963,7 @@ Dan Kenigsberg
|
||||||
Randall Kern
|
Randall Kern
|
||||||
Robert Kern
|
Robert Kern
|
||||||
Jim Kerr
|
Jim Kerr
|
||||||
|
Jazz Kersell
|
||||||
Magnus Kessler
|
Magnus Kessler
|
||||||
Lawrence Kesteloot
|
Lawrence Kesteloot
|
||||||
Garvit Khatri
|
Garvit Khatri
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Add an example of how to generate test cases to load with load_tests
|
||||||
Loading…
Add table
Add a link
Reference in a new issue