diff --git a/AUTHORS b/AUTHORS index 9c3cb6a12..1641ea15e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -98,6 +98,7 @@ Javier Domingo Cansino Javier Romero Jeff Rackauckas Jeff Widman +Jenni Rinker John Eddie Ayson John Towler Jon Sonesen diff --git a/changelog/3824.doc.rst b/changelog/3824.doc.rst new file mode 100644 index 000000000..016065120 --- /dev/null +++ b/changelog/3824.doc.rst @@ -0,0 +1 @@ +Added example for multiple glob pattern matches in ``python_files``. diff --git a/doc/en/example/pythoncollection.rst b/doc/en/example/pythoncollection.rst index 8e9d3ae62..6c86b8a63 100644 --- a/doc/en/example/pythoncollection.rst +++ b/doc/en/example/pythoncollection.rst @@ -100,8 +100,10 @@ Changing naming conventions You can configure different naming conventions by setting the :confval:`python_files`, :confval:`python_classes` and -:confval:`python_functions` configuration options. Example:: +:confval:`python_functions` configuration options. +Here is an example:: + # Example 1: have pytest look for "check" instead of "test" # content of pytest.ini # can also be defined in tox.ini or setup.cfg file, although the section # name in setup.cfg files should be "tool:pytest" @@ -112,7 +114,7 @@ the :confval:`python_files`, :confval:`python_classes` and This would make ``pytest`` look for tests in files that match the ``check_* .py`` glob-pattern, ``Check`` prefixes in classes, and functions and methods -that match ``*_check``. For example, if we have:: +that match ``*_check``. For example, if we have:: # content of check_myapp.py class CheckMyApp(object): @@ -121,7 +123,7 @@ that match ``*_check``. For example, if we have:: def complex_check(self): pass -then the test collection looks like this:: +The test collection would look like this:: $ pytest --collect-only =========================== test session starts ============================ @@ -136,6 +138,14 @@ then the test collection looks like this:: ======================= no tests ran in 0.12 seconds ======================= +You can check for multiple glob patterns by adding a space between the patterns:: + + # Example 2: have pytest look for files with "test" and "example" + # content of pytest.ini, tox.ini, or setup.cfg file (replace "pytest" + # with "tool:pytest" for setup.cfg) + [pytest] + python_files=test_*.py example_*.py + .. note:: the ``python_functions`` and ``python_classes`` options has no effect diff --git a/doc/en/reference.rst b/doc/en/reference.rst index 484c755da..28fc6805a 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -1229,7 +1229,8 @@ passed multiple times. The expected format is ``name=value``. For example:: .. confval:: python_classes One or more name prefixes or glob-style patterns determining which classes - are considered for test collection. By default, pytest will consider any + are considered for test collection. Search for multiple glob patterns by + adding a space between patterns. By default, pytest will consider any class prefixed with ``Test`` as a test collection. Here is an example of how to collect tests from classes that end in ``Suite``: @@ -1246,15 +1247,23 @@ passed multiple times. The expected format is ``name=value``. For example:: .. confval:: python_files One or more Glob-style file patterns determining which python files - are considered as test modules. By default, pytest will consider - any file matching with ``test_*.py`` and ``*_test.py`` globs as a test - module. + are considered as test modules. Search for multiple glob patterns by + adding a space between patterns:: + + .. code-block:: ini + + [pytest] + python_files = test_*.py check_*.py example_*.py + + By default, pytest will consider any file matching with ``test_*.py`` + and ``*_test.py`` globs as a test module. .. confval:: python_functions One or more name prefixes or glob-patterns determining which test functions - and methods are considered tests. By default, pytest will consider any + and methods are considered tests. Search for multiple glob patterns by + adding a space between patterns. By default, pytest will consider any function prefixed with ``test`` as a test. Here is an example of how to collect test functions and methods that end in ``_test``: