Skip to content

Commit

Permalink
Merge pull request #131 from lahdjirayhan/mark-slow-tests
Browse files Browse the repository at this point in the history
test: Mark slow tests
  • Loading branch information
Milind220 committed Apr 25, 2022
2 parents 9f46ddc + 37c139e commit d626295
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
from utils import vcr_kwargs, DEFAULT_OUTPUT_FOLDER


# Pytest configurations. Modified from
# https://docs.pytest.org/en/7.1.x/example/simple.html#control-skipping-of-tests-according-to-command-line-option

# Add option for CLI invocation
def pytest_addoption(parser):
parser.addoption(
"--skip-slow", action="store_true", default=False, help="skip slow tests"
)


# Register pytest.mark.slow
def pytest_configure(config):
config.addinivalue_line("markers", "slow: mark test as slow to run")


# Skip slow tests unless --run_slow is given
def pytest_collection_modifyitems(config, items):
if config.getoption("--skip-slow"):
skip_slow = pytest.mark.skip(reason="skipped due to --skip-slow")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)


# Configuration fixture for pytest-vcr
@pytest.fixture(scope="session")
def vcr_config():
Expand Down
8 changes: 5 additions & 3 deletions tests/test_get_historical_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
)


# Filterwarnings from: https://stackoverflow.com/a/58645998/11316205
@pytest.mark.vcr
@pytest.mark.filterwarnings(
"ignore::UserWarning"
) # https://stackoverflow.com/a/58645998/11316205
@pytest.mark.slow
@pytest.mark.filterwarnings("ignore::UserWarning")
def test_return_value_and_format():
result = api.get_historical_data(city="london")
assert isinstance(result, pandas.DataFrame)


@pytest.mark.vcr
@pytest.mark.slow
def test_warnings_on_input_combo():
with pytest.warns(UserWarning, match="city_id was not supplied"):
api.get_historical_data(city="london")
Expand All @@ -37,6 +38,7 @@ def test_arguments_not_named():


@pytest.mark.vcr
@pytest.mark.slow
@pytest.mark.parametrize("fmt", SUPPORTED_OUTPUT_FORMATS)
@pytest.mark.filterwarnings("ignore::UserWarning")
def test_output_data_formats(fmt):
Expand Down

0 comments on commit d626295

Please sign in to comment.