Skip to content

Commit

Permalink
Change pytest --testsuite-description option to accept a regex
Browse files Browse the repository at this point in the history
  • Loading branch information
marksparkza committed Nov 18, 2023
1 parent df3c840 commit ca20c7e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Deprecation removals:
* Exception classes dropped from the top-level package API
* ``jschon.exceptions`` module renamed to ``jschon.exc``

Miscellaneous:

* pytest ``--testsuite-description`` option now takes a regex

v0.11.1 (2023-10-22)
--------------------
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ of the test suite, jschon provides the following pytest command line options::
--testsuite-optionals and --testsuite-formats to be
ignored.
--testsuite-description=TESTSUITE_DESCRIPTION
Run only test groups and tests whose descriptions
contain the given substring. Matching is case
insensitive. The option may be repeated to match
alternative substrings.
Run only tests where the test or test case description
matches the given regular expression. Matching is case
insensitive and not anchored to the start or end of
string.
--testsuite-generate-status
Run all possible tests from all supported versions and
update the tests/suite_status.json file. If a failed
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def pytest_addoption(parser):
)
testsuite.addoption(
"--testsuite-description",
action="append",
help="Run only test groups and tests whose descriptions contain the given substring. "
"Matching is case insensitive. The option may be repeated to match alternative substrings.",
action="store",
help="Run only tests where the test or test case description matches the given regular "
"expression. Matching is case insensitive and not anchored to the start or end of string.",
)
testsuite.addoption(
"--testsuite-generate-status",
Expand Down
14 changes: 9 additions & 5 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import pathlib
import re
import warnings

import pytest
Expand Down Expand Up @@ -101,13 +102,15 @@ def pytest_generate_tests(metafunc):
include_optionals = True
include_formats = True
test_files = []
test_descriptions = []
testsuite_description = None
else:
test_versions = metafunc.config.getoption("testsuite_version")
include_optionals = metafunc.config.getoption("testsuite_optionals")
include_formats = metafunc.config.getoption("testsuite_formats")
test_files = metafunc.config.getoption("testsuite_file")
test_descriptions = metafunc.config.getoption("testsuite_description")
testsuite_description = metafunc.config.getoption("testsuite_description")

description_regex = re.compile(testsuite_description, re.IGNORECASE) if testsuite_description else None

if not test_versions:
test_versions = ['2019-09', '2020-12']
Expand Down Expand Up @@ -143,9 +146,10 @@ def pytest_generate_tests(metafunc):
testcases = json_loadf(testfile_path)
for testcase in testcases:
for test in testcase['tests']:
if test_descriptions and not any(
s.lower() in testcase['description'].lower() or s.lower() in test['description'].lower()
for s in test_descriptions
if (
description_regex
and description_regex.search(test['description']) is None
and description_regex.search(testcase['description']) is None
):
continue

Expand Down

0 comments on commit ca20c7e

Please sign in to comment.