From 0cc8768097d0b1fcc66261c69c59cd1aa6856d4c Mon Sep 17 00:00:00 2001 From: Nuclear03020704 <52926983+lahdjirayhan@users.noreply.github.com> Date: Mon, 25 Apr 2022 00:13:14 +0700 Subject: [PATCH 1/2] test: Add way to mark and skip slow tests --- tests/conftest.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 6798f60..f0ff077 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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(): From 7847501a1ef95fd4e0c36c607a5594b9802fad65 Mon Sep 17 00:00:00 2001 From: Nuclear03020704 <52926983+lahdjirayhan@users.noreply.github.com> Date: Mon, 25 Apr 2022 00:18:21 +0700 Subject: [PATCH 2/2] test: Mark slow tests --- tests/test_get_historical_data.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_get_historical_data.py b/tests/test_get_historical_data.py index e16bf1a..ddf0040 100644 --- a/tests/test_get_historical_data.py +++ b/tests/test_get_historical_data.py @@ -4,16 +4,17 @@ from utils import api, DEFAULT_OUTPUT_FOLDER, DEFAULT_OUTPUT_FILE +# 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") @@ -32,6 +33,7 @@ def test_arguments_not_named(): @pytest.mark.vcr +@pytest.mark.slow @pytest.mark.filterwarnings("ignore::UserWarning") def test_correct_data_format(): # Not specifying data format shouldn't create an output directory