Merge pull request #3856 from jennirinker/master

Resolving Issue #3824
This commit is contained in:
Bruno Oliveira 2018-08-22 19:03:55 -03:00 committed by GitHub
commit 17eec5b97e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 12 deletions

View File

@ -98,6 +98,7 @@ Javier Domingo Cansino
Javier Romero Javier Romero
Jeff Rackauckas Jeff Rackauckas
Jeff Widman Jeff Widman
Jenni Rinker
John Eddie Ayson John Eddie Ayson
John Towler John Towler
Jon Sonesen Jon Sonesen

1
changelog/3824.doc.rst Normal file
View File

@ -0,0 +1 @@
Added example for multiple glob pattern matches in ``python_files``.

View File

@ -100,19 +100,21 @@ Changing naming conventions
You can configure different naming conventions by setting You can configure different naming conventions by setting
the :confval:`python_files`, :confval:`python_classes` and 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 # content of pytest.ini
# can also be defined in tox.ini or setup.cfg file, although the section # can also be defined in tox.ini or setup.cfg file, although the section
# name in setup.cfg files should be "tool:pytest" # name in setup.cfg files should be "tool:pytest"
[pytest] [pytest]
python_files=check_*.py python_files = check_*.py
python_classes=Check python_classes = Check
python_functions=*_check python_functions = *_check
This would make ``pytest`` look for tests in files that match the ``check_* This would make ``pytest`` look for tests in files that match the ``check_*
.py`` glob-pattern, ``Check`` prefixes in classes, and functions and methods .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 # content of check_myapp.py
class CheckMyApp(object): class CheckMyApp(object):
@ -121,7 +123,7 @@ that match ``*_check``. For example, if we have::
def complex_check(self): def complex_check(self):
pass pass
then the test collection looks like this:: The test collection would look like this::
$ pytest --collect-only $ pytest --collect-only
=========================== test session starts ============================ =========================== test session starts ============================
@ -136,11 +138,19 @@ then the test collection looks like this::
======================= no tests ran in 0.12 seconds ======================= ======================= 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:: .. note::
the ``python_functions`` and ``python_classes`` options has no effect the ``python_functions`` and ``python_classes`` options has no effect
for ``unittest.TestCase`` test discovery because pytest delegates for ``unittest.TestCase`` test discovery because pytest delegates
detection of test case methods to unittest code. discovery of test case methods to unittest code.
Interpreting cmdline arguments as Python packages Interpreting cmdline arguments as Python packages
----------------------------------------------------- -----------------------------------------------------

View File

@ -1229,7 +1229,8 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: python_classes .. confval:: python_classes
One or more name prefixes or glob-style patterns determining which 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 class prefixed with ``Test`` as a test collection. Here is an example of how
to collect tests from classes that end in ``Suite``: 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 .. confval:: python_files
One or more Glob-style file patterns determining which python files One or more Glob-style file patterns determining which python files
are considered as test modules. By default, pytest will consider are considered as test modules. Search for multiple glob patterns by
any file matching with ``test_*.py`` and ``*_test.py`` globs as a test adding a space between patterns::
module.
.. 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 .. confval:: python_functions
One or more name prefixes or glob-patterns determining which test 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 function prefixed with ``test`` as a test. Here is an example of how
to collect test functions and methods that end in ``_test``: to collect test functions and methods that end in ``_test``: