Created
December 8, 2019 13:19
-
-
Save boxabirds/0b8969a26e7fccd6cd7d0c8c0f8b87bb to your computer and use it in GitHub Desktop.
pytest.mark.chargeable: exclude tests that may incur a charge from the cloud provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inspired by example in https://docs.pytest.org/en/latest/example/simple.html | |
import pytest | |
def pytest_addoption(parser): | |
parser.addoption( | |
"--runchargeable", action="store_true", default=False, help="run tests that may incur a charge" | |
) | |
def pytest_configure(config): | |
config.addinivalue_line("markers", "unit: unit test only, with mocked SaaS connections") | |
config.addinivalue_line("markers", "chargeable: running this test could incur cloud service charges") | |
def pytest_collection_modifyitems(config, items): | |
if config.getoption("--runchargeable"): | |
# --runchargeable given in cli: do not skip tests that may incur a charge | |
return | |
skip_chargeable = pytest.mark.skip(reason="need --runchargeable option to run") | |
for item in items: | |
if "chargeable" in item.keywords: | |
item.add_marker(skip_chargeable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment