mirror of
https://github.com/DOI-DO/j40-cejst-2.git
synced 2025-07-29 17:41:17 -07:00
Issue 1075: update snapshots using command-line flag (#1249)
* Adding skippable tests using command-line flag
This commit is contained in:
parent
a0d6e55f0a
commit
3e37d9d1a3
4 changed files with 115 additions and 31 deletions
40
data/data-pipeline/conftest.py
Normal file
40
data/data-pipeline/conftest.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import pytest
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
"""Adds --update_snapshots as an optional flag that can be parsed from the
|
||||
command line when calling pytest
|
||||
"""
|
||||
parser.addoption(
|
||||
"--update_snapshots",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Update snapshot test fixtures",
|
||||
)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
"""Adds update_snapshots to list of available markers to apply to tests"""
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
"update_snapshots: mark test as one that updates snapshot fixtures",
|
||||
)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
"""Applies pytest.mark.skip to all tests marked with update_snapshots
|
||||
unless the --update_snapshots flag is passed to the CLI
|
||||
"""
|
||||
# if --update_snapshots passed in cli
|
||||
if config.getoption("--update_snapshots"):
|
||||
# only run the tests marked with update_snapshots
|
||||
skip = pytest.mark.skip(reason="only updating snapshots")
|
||||
for test in items:
|
||||
if "update_snapshots" not in test.keywords:
|
||||
test.add_marker(skip)
|
||||
else:
|
||||
# otherwise skip all tests marked with update_snapshots
|
||||
skip = pytest.mark.skip(reason="must pass --update_snapshots to run")
|
||||
for test in items:
|
||||
if "update_snapshots" in test.keywords:
|
||||
test.add_marker(skip)
|
Loading…
Add table
Add a link
Reference in a new issue