Skip to content

Commit 3598117

Browse files
committed
Add --testsuite-description pytest option
1 parent e77ae75 commit 3598117

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Miscellaneous:
3838
* Remove implicit fall-through to looking up a schema in the `__meta__` cache
3939
if not found in the parameterized cache, in ``Catalog.get_schema()`` (#40)
4040
* Improve kwarg-based construction of ``RelativeJSONPointer``
41-
* Allow passthrough of arguments to ``pytest`` when invoking ``tox``
41+
* Allow passthrough of arguments to pytest when invoking tox
42+
* Add pytest command line options ``--testsuite-file`` and ``--testsuite-description``
4243
* Python 3.11 is now tested (no changes were required to support it)
4344
* Pinned ``hypothesis<6.0.4`` to avoid
4445
`python/cpython#102126 <https://github.com/python/cpython/issues/102126>`_

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def pytest_addoption(parser):
3535
action="append",
3636
help="Run only this file from the JSON Schema test suite. The option may be repeated to run multiple files. Using this option causes --testsuite-optionals and --testsuite-formats to be ignored"
3737
)
38+
testsuite.addoption(
39+
"--testsuite-description",
40+
action="append",
41+
help="Run only test groups and tests whose descriptions contain the given substring. "
42+
"Matching is case insensitive. The option may be repeated.",
43+
)
3844

3945

4046
@pytest.fixture(scope='module', autouse=True)

tests/test_suite.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def pytest_generate_tests(metafunc):
4545
include_optionals = metafunc.config.getoption("testsuite_optionals")
4646
include_formats = metafunc.config.getoption("testsuite_formats")
4747
test_files = metafunc.config.getoption("testsuite_file")
48+
test_descriptions = metafunc.config.getoption("testsuite_description")
4849

4950
base_dir = testsuite_dir / 'tests'
5051
version_dirs = {
@@ -77,6 +78,12 @@ def pytest_generate_tests(metafunc):
7778
testcases = json_loadf(testfile_path)
7879
for testcase in testcases:
7980
for test in testcase['tests']:
81+
if test_descriptions and not any(
82+
s.lower() in testcase['description'].lower() or s.lower() in test['description'].lower()
83+
for s in test_descriptions
84+
):
85+
continue
86+
8087
argvalues.append(pytest.param(metaschema_uri, testcase['schema'], test['data'], test['valid']))
8188
testids.append(f"{version} -> {testfile_path.name} -> {testcase['description']} -> {test['description']}")
8289

0 commit comments

Comments
 (0)