Skip to content

Commit

Permalink
pytest: add option --repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Aug 2, 2024
1 parent 6a62b0c commit d47cc39
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions qwt/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,28 @@ def pytest_report_header(config):
f"PythonQwt {qwt.__version__} [closest Qwt version: {qwt.QWT_VERSION_STR}]",
f"{qtpy.API_NAME} {qtbindings_version} [Qt version: {qtpy.QT_VERSION}]",
]


def pytest_addoption(parser):
"""Add custom command line options to pytest."""
# See this StackOverflow answer for more information: https://t.ly/9anqz
parser.addoption(
"--repeat", action="store", help="Number of times to repeat each test"
)


def pytest_generate_tests(metafunc):
"""Generate tests for the given metafunc."""
# See this StackOverflow answer for more information: https://t.ly/9anqz
if metafunc.config.option.repeat is not None:
count = int(metafunc.config.option.repeat)

# We're going to duplicate these tests by parametrizing them,
# which requires that each test has a fixture to accept the parameter.
# We can add a new fixture like so:
metafunc.fixturenames.append("tmp_ct")

# Now we parametrize. This is what happens when we do e.g.,
# @pytest.mark.parametrize('tmp_ct', range(count))
# def test_foo(): pass
metafunc.parametrize("tmp_ct", range(count))

0 comments on commit d47cc39

Please sign in to comment.