From a12eadd9ef32a8312d49669d98aa533247db2fec Mon Sep 17 00:00:00 2001 From: Jennifer Rinker Date: Wed, 22 Aug 2018 15:37:35 +0200 Subject: [PATCH 1/2] resolving Issue #3824 - expanding docs --- AUTHORS | 1 + changelog/3824.doc.rst | 1 + doc/en/example/pythoncollection.rst | 16 +++++++++++++--- doc/en/reference.rst | 19 ++++++++++++++----- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 changelog/3824.doc.rst 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``: From 5a7aa123ea29987287a4e01b8e61aacce282cd40 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 22 Aug 2018 11:22:30 -0300 Subject: [PATCH 2/2] Improve docs formatting --- doc/en/example/pythoncollection.rst | 10 +++++----- doc/en/reference.rst | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/en/example/pythoncollection.rst b/doc/en/example/pythoncollection.rst index 6c86b8a63..b4950a75c 100644 --- a/doc/en/example/pythoncollection.rst +++ b/doc/en/example/pythoncollection.rst @@ -108,9 +108,9 @@ Here is an example:: # can also be defined in tox.ini or setup.cfg file, although the section # name in setup.cfg files should be "tool:pytest" [pytest] - python_files=check_*.py - python_classes=Check - python_functions=*_check + python_files = check_*.py + python_classes = Check + python_functions = *_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 @@ -144,13 +144,13 @@ You can check for multiple glob patterns by adding a space between the patterns: # 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 + python_files = test_*.py example_*.py .. note:: the ``python_functions`` and ``python_classes`` options has no effect 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 ----------------------------------------------------- diff --git a/doc/en/reference.rst b/doc/en/reference.rst index 28fc6805a..042df9687 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -1255,7 +1255,7 @@ passed multiple times. The expected format is ``name=value``. For example:: [pytest] python_files = test_*.py check_*.py example_*.py - By default, pytest will consider any file matching with ``test_*.py`` + By default, pytest will consider any file matching with ``test_*.py`` and ``*_test.py`` globs as a test module.