Skip to content

Commit

Permalink
📝 Add git filter for pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
veit committed May 26, 2024
1 parent d4d7c6d commit 5b26b98
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions docs/test/pytest/testsuite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,29 @@ Executing a small group of tests is very handy when debugging, or if you want to
limit the tests to a specific section of the codebase you are working on. pytest
allows you to execute a subset of tests in different ways:

+-------------------------------+-----------------------------------------------------------------------+
| Subset | Syntax |
+===============================+=======================================================================+
| All tests in one directory | :samp:`pytest {path}` |
+-------------------------------+-----------------------------------------------------------------------+
| All tests in a module | :samp:`pytest {path}/test_{module}.py` |
+-------------------------------+-----------------------------------------------------------------------+
| All tests in a class | :samp:`pytest {path}/test_{module}.py::Test{Class}` |
+-------------------------------+-----------------------------------------------------------------------+
| Single test function | :samp:`pytest {path}/test_{module}.py::test_{function}` |
+-------------------------------+-----------------------------------------------------------------------+
| Single test method | :samp:`pytest {path}/test_{module}.py::Test{Class}::test_{method}` |
+-------------------------------+-----------------------------------------------------------------------+
| Tests that correspond to a | :samp:`pytest -k {pattern}` |
| name pattern | |
+-------------------------------+-----------------------------------------------------------------------+
| Tests by marker | siehe :doc:`markers` |
+-------------------------------+-----------------------------------------------------------------------+
+-----------------------------------------------+-----------------------------------------------------------------------+
| Subset | Syntax |
+===============================================+=======================================================================+
| All tests in one directory | :samp:`pytest {path}` |
+-----------------------------------------------+-----------------------------------------------------------------------+
| All tests in a module | :samp:`pytest {path}/test_{module}.py` |
+-----------------------------------------------+-----------------------------------------------------------------------+
| All files changed in the working directory of | :samp:`pytest $(git diff --name-only 'tests/test_*.py')` |
| a :doc:`Git | |
| <Python4DataScience:productive/git/index>` | |
| repository | |
+-----------------------------------------------+-----------------------------------------------------------------------+
| All tests in a class | :samp:`pytest {path}/test_{module}.py::Test{Class}` |
+-----------------------------------------------+-----------------------------------------------------------------------+
| Single test function | :samp:`pytest {path}/test_{module}.py::test_{function}` |
+-----------------------------------------------+-----------------------------------------------------------------------+
| Single test method | :samp:`pytest {path}/test_{module}.py::Test{Class}::test_{method}` |
+-----------------------------------------------+-----------------------------------------------------------------------+
| Tests that correspond to a | :samp:`pytest -k {pattern}` |
| name pattern | |
+-----------------------------------------------+-----------------------------------------------------------------------+
| Tests by marker | siehe :doc:`markers` |
+-----------------------------------------------+-----------------------------------------------------------------------+

Whether ``pytest`` finds your test code depends on the naming:

Expand Down

0 comments on commit 5b26b98

Please sign in to comment.