Unverified Commit 8715d20c authored by Stas Bekman's avatar Stas Bekman Committed by GitHub
Browse files

[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
parent f20d75a1
...@@ -151,7 +151,6 @@ As mentioned earlier you can see what tests are contained inside the ``Optimizat ...@@ -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``: ...@@ -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``: ...@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment