j40-cejst-2/data/data-pipeline/conftest.py
Lucas Merrill Brown 3e37d9d1a3
Issue 1075: update snapshots using command-line flag (#1249)
* Adding skippable tests using command-line flag
2022-02-14 12:16:52 -05:00

40 lines
1.3 KiB
Python

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)