2020-04-27 08:14:53 +00:00
|
|
|
import pytest
|
2021-07-20 13:07:49 +00:00
|
|
|
|
|
|
|
|
2020-04-27 08:14:53 +00:00
|
|
|
def pytest_addoption(parser):
|
2021-07-20 13:07:49 +00:00
|
|
|
parser.addoption(
|
|
|
|
"-E",
|
|
|
|
action="append",
|
|
|
|
metavar="NAME",
|
|
|
|
help="only run tests matching the environment NAME.",
|
|
|
|
)
|
|
|
|
|
2020-04-27 08:14:53 +00:00
|
|
|
|
|
|
|
def pytest_configure(config):
|
|
|
|
# register an additional marker
|
2021-07-20 13:07:49 +00:00
|
|
|
config.addinivalue_line(
|
|
|
|
"markers",
|
|
|
|
"env(name): mark test to run only on named environment",
|
|
|
|
)
|
2021-09-15 15:00:08 +00:00
|
|
|
config.addinivalue_line("markers", "replace_module_value")
|
|
|
|
config.addinivalue_line("markers", "masked_modules")
|
|
|
|
config.addinivalue_line("markers", "ensured_modules")
|
|
|
|
config.addinivalue_line("markers", "sleepdeprived_patched_module")
|
2021-07-20 13:07:49 +00:00
|
|
|
|
2020-04-27 08:14:53 +00:00
|
|
|
|
|
|
|
def pytest_runtest_setup(item):
|
|
|
|
envnames = [mark.args[0] for mark in item.iter_markers(name='env')]
|
|
|
|
if envnames:
|
2021-07-20 13:07:49 +00:00
|
|
|
if (
|
|
|
|
item.config.getoption("-E") is None
|
|
|
|
or len(set(item.config.getoption("-E")) & set(envnames)) == 0
|
|
|
|
):
|
2020-04-27 08:14:53 +00:00
|
|
|
# We skip test if does not mentioned by -E param
|
|
|
|
pytest.skip("test requires env in %r" % envnames)
|