[doc] [testing] extend the pytest -k section with more examples (#10761)
* [doc] [testing] extend -k section This PR adds more examples on using `pytest -k` - I always forget that I want to use `-k A OR B` when I want several tests - I keep trying AND and it doesn't match any. * style
This commit is contained in:
@@ -151,7 +151,6 @@ As mentioned earlier you can see what tests are contained inside the ``Optimizat
|
|||||||
|
|
||||||
pytest tests/test_optimization.py::OptimizationTest --collect-only -q
|
pytest tests/test_optimization.py::OptimizationTest --collect-only -q
|
||||||
|
|
||||||
|
|
||||||
You can run tests by keyword expressions.
|
You can run tests by keyword expressions.
|
||||||
|
|
||||||
To run only tests whose name contains ``adam``:
|
To run only tests whose name contains ``adam``:
|
||||||
@@ -160,6 +159,9 @@ To run only tests whose name contains ``adam``:
|
|||||||
|
|
||||||
pytest -k adam tests/test_optimization.py
|
pytest -k adam tests/test_optimization.py
|
||||||
|
|
||||||
|
Logical ``and`` and ``or`` can be used to indicate whether all keywords should match or either. ``not`` can be used to
|
||||||
|
negate.
|
||||||
|
|
||||||
To run all tests except those whose name contains ``adam``:
|
To run all tests except those whose name contains ``adam``:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
@@ -168,11 +170,24 @@ To run all tests except those whose name contains ``adam``:
|
|||||||
|
|
||||||
And you can combine the two patterns in one:
|
And you can combine the two patterns in one:
|
||||||
|
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
pytest -k "ada and not adam" tests/test_optimization.py
|
pytest -k "ada and not adam" tests/test_optimization.py
|
||||||
|
|
||||||
|
For example to run both ``test_adafactor`` and ``test_adam_w`` you can use:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
pytest -k "test_adam_w or test_adam_w" tests/test_optimization.py
|
||||||
|
|
||||||
|
Note that we use ``or`` here, since we want either of the keywords to match to include both.
|
||||||
|
|
||||||
|
If you want to include only tests that include both patterns, ``and`` is to be used:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
pytest -k "test and ada" tests/test_optimization.py
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Run only modified tests
|
Run only modified tests
|
||||||
|
|||||||
Reference in New Issue
Block a user