@@ -1561,7 +1561,7 @@ Loading and running tests
1561
1561
:class: `testCaseClass `.
1562
1562
1563
1563
1564
- .. method :: loadTestsFromModule(module)
1564
+ .. method :: loadTestsFromModule(module, pattern=None )
1565
1565
1566
1566
Return a suite of all tests cases contained in the given module. This
1567
1567
method searches *module * for classes derived from :class: `TestCase ` and
@@ -1578,11 +1578,18 @@ Loading and running tests
1578
1578
1579
1579
If a module provides a ``load_tests `` function it will be called to
1580
1580
load the tests. This allows modules to customize test loading.
1581
- This is the `load_tests protocol `_.
1581
+ This is the `load_tests protocol `_. The *pattern * argument is passed as
1582
+ the third argument to ``load_tests ``.
1582
1583
1583
1584
.. versionchanged :: 3.2
1584
1585
Support for ``load_tests `` added.
1585
1586
1587
+ .. versionchanged :: 3.5
1588
+ The undocumented and unofficial *use_load_tests * default argument is
1589
+ deprecated and ignored, although it is still accepted for backward
1590
+ compatibility. The method also now accepts a keyword-only argument
1591
+ *pattern * which is passed to ``load_tests `` as the third argument.
1592
+
1586
1593
1587
1594
.. method :: loadTestsFromName(name, module=None)
1588
1595
@@ -1634,18 +1641,18 @@ Loading and running tests
1634
1641
the start directory is not the top level directory then the top level
1635
1642
directory must be specified separately.
1636
1643
1637
- If importing a module fails, for example due to a syntax error, then this
1638
- will be recorded as a single error and discovery will continue. If the
1639
- import failure is due to :exc: `SkipTest ` being raised, it will be recorded
1640
- as a skip instead of an error.
1644
+ If importing a module fails, for example due to a syntax error, then
1645
+ this will be recorded as a single error and discovery will continue. If
1646
+ the import failure is due to :exc: `SkipTest ` being raised, it will be
1647
+ recorded as a skip instead of an error.
1641
1648
1642
- If a test package name (directory with :file: `__init__.py `) matches the
1643
- pattern then the package will be checked for a ``load_tests ``
1644
- function. If this exists then it will be called with *loader *, *tests *,
1645
- *pattern *.
1649
+ If a package (a directory containing a file named :file: `__init__.py `) is
1650
+ found, the package will be checked for a ``load_tests `` function. If this
1651
+ exists then it will be called with *loader *, *tests *, *pattern *.
1646
1652
1647
- If load_tests exists then discovery does *not * recurse into the package,
1648
- ``load_tests `` is responsible for loading all tests in the package.
1653
+ If ``load_tests `` exists then discovery does *not * recurse into the
1654
+ package, ``load_tests `` is responsible for loading all tests in the
1655
+ package.
1649
1656
1650
1657
The pattern is deliberately not stored as a loader attribute so that
1651
1658
packages can continue discovery themselves. *top_level_dir * is stored so
@@ -1664,6 +1671,11 @@ Loading and running tests
1664
1671
the same even if the underlying file system's ordering is not
1665
1672
dependent on file name.
1666
1673
1674
+ .. versionchanged :: 3.5
1675
+ Found packages are now checked for ``load_tests `` regardless of
1676
+ whether their path matches *pattern *, because it is impossible for
1677
+ a package name to match the default pattern.
1678
+
1667
1679
1668
1680
The following attributes of a :class: `TestLoader ` can be configured either by
1669
1681
subclassing or assignment on an instance:
@@ -2032,7 +2044,10 @@ test runs or test discovery by implementing a function called ``load_tests``.
2032
2044
If a test module defines ``load_tests `` it will be called by
2033
2045
:meth: `TestLoader.loadTestsFromModule ` with the following arguments::
2034
2046
2035
- load_tests(loader, standard_tests, None)
2047
+ load_tests(loader, standard_tests, pattern)
2048
+
2049
+ where *pattern * is passed straight through from ``loadTestsFromModule ``. It
2050
+ defaults to ``None ``.
2036
2051
2037
2052
It should return a :class: `TestSuite `.
2038
2053
@@ -2054,21 +2069,12 @@ A typical ``load_tests`` function that loads tests from a specific set of
2054
2069
suite.addTests(tests)
2055
2070
return suite
2056
2071
2057
- If discovery is started, either from the command line or by calling
2058
- :meth: `TestLoader.discover `, with a pattern that matches a package
2059
- name then the package :file: `__init__.py ` will be checked for ``load_tests ``.
2060
-
2061
- .. note ::
2062
-
2063
- The default pattern is ``'test*.py' ``. This matches all Python files
2064
- that start with ``'test' `` but *won't * match any test directories.
2065
-
2066
- A pattern like ``'test*' `` will match test packages as well as
2067
- modules.
2068
-
2069
- If the package :file: `__init__.py ` defines ``load_tests `` then it will be
2070
- called and discovery not continued into the package. ``load_tests ``
2071
- is called with the following arguments::
2072
+ If discovery is started in a directory containing a package, either from the
2073
+ command line or by calling :meth: `TestLoader.discover `, then the package
2074
+ :file: `__init__.py ` will be checked for ``load_tests ``. If that function does
2075
+ not exist, discovery will recurse into the package as though it were just
2076
+ another directory. Otherwise, discovery of the package's tests will be left up
2077
+ to ``load_tests `` which is called with the following arguments::
2072
2078
2073
2079
load_tests(loader, standard_tests, pattern)
2074
2080
@@ -2087,6 +2093,11 @@ continue (and potentially modify) test discovery. A 'do nothing'
2087
2093
standard_tests.addTests(package_tests)
2088
2094
return standard_tests
2089
2095
2096
+ .. versionchanged :: 3.5
2097
+ Discovery no longer checks package names for matching *pattern * due to the
2098
+ impossibility of package names matching the default pattern.
2099
+
2100
+
2090
2101
2091
2102
Class and Module Fixtures
2092
2103
-------------------------
0 commit comments