Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-31141: Add test decorators for cartesian product #490

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions python/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,27 @@ will run tests:
Note that the method being decorated must be within a subclass of ``unittest.TestCase``, since it relies on the existence of the ``subTest`` method for identifying the individual iterations.
This use of ``subTest`` also means that all iterations will be executed, not stopping at the first failure.

``classParameters`` and ``methodParameters`` require listing all combinations of the parameters.
If you want to instead iterate over all possible combinations of the parameters,
use ``classParametersProduct`` and ``methodParametersProduct``.
For example:

.. code-block:: python

class MyTestCase(unittest.TestCase):
@methodParametersProduct(foo=[1, 2], bar=["black", "white"])
def testSomething(self, foo, bar):
...

will run tests:

.. code-block:: python

testSomething(foo=1, bar="black")
testSomething(foo=1, bar="white")
testSomething(foo=2, bar="black")
testSomething(foo=2, bar="white")

See also ``pytest.mark.parametrize``, which is more complex but offers similar functionality;
however, this module is not yet approved for use.

Expand Down