From 8715d20c97b3975c1d89cf0c0cca45af91badd1d Mon Sep 17 00:00:00 2001 From: Stas Bekman Date: Wed, 17 Mar 2021 06:23:38 -0700 Subject: [PATCH] [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 --- docs/source/testing.rst | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/source/testing.rst b/docs/source/testing.rst index 4dffe15b9e..10ad3e2311 100644 --- a/docs/source/testing.rst +++ b/docs/source/testing.rst @@ -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 - You can run tests by keyword expressions. 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 +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``: .. 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: - .. code-block:: bash 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