from test_fixtures.plugin import active_tags_from_env pytest_plugins = ['pytester'] _TEST_FILES = { 'test_alpha': """ import pytest pytestmark = pytest.mark.lambda_name('alpha') def test_a(): pass """, 'test_beta': """ import pytest pytestmark = pytest.mark.lambda_name('beta') def test_b(): pass """, } def test_active_tags_from_env(monkeypatch): monkeypatch.setenv('LAMBDA_FUNCTION_NAMES', 'a, b ,c') assert active_tags_from_env() == {'a', 'b', 'c'} monkeypatch.setenv('LAMBDA_FUNCTION_NAMES', ' ') assert active_tags_from_env() == set() monkeypatch.delenv('LAMBDA_FUNCTION_NAMES', raising=False) assert active_tags_from_env() == set() def test_empty_env_runs_all(pytester, monkeypatch): monkeypatch.delenv('LAMBDA_FUNCTION_NAMES', raising=False) pytester.makepyfile(**_TEST_FILES) pytester.runpytest_inprocess().assert_outcomes(passed=2) def test_filters_to_named_lambda(pytester, monkeypatch): monkeypatch.setenv('LAMBDA_FUNCTION_NAMES', 'alpha') pytester.makepyfile(**_TEST_FILES) pytester.runpytest_inprocess().assert_outcomes(passed=1, deselected=1) def test_always_deselect_lambdas_ini(pytester, monkeypatch): monkeypatch.delenv('LAMBDA_FUNCTION_NAMES', raising=False) pytester.makeini( """ [pytest] always_deselect_lambdas = beta """ ) pytester.makepyfile(**_TEST_FILES) # beta is always deselected unless named; alpha (a normal tag) still runs. pytester.runpytest_inprocess().assert_outcomes(passed=1, deselected=1) def test_always_deselect_lambda_runs_when_named(pytester, monkeypatch): monkeypatch.setenv('LAMBDA_FUNCTION_NAMES', 'beta') pytester.makeini( """ [pytest] always_deselect_lambdas = beta """ ) pytester.makepyfile(**_TEST_FILES) pytester.runpytest_inprocess().assert_outcomes(passed=1, deselected=1) def test_marker_is_registered(pytester, monkeypatch): monkeypatch.delenv('LAMBDA_FUNCTION_NAMES', raising=False) pytester.makepyfile(**_TEST_FILES) # --strict-markers would error on collection if the marker were unregistered. pytester.runpytest_inprocess('--strict-markers').assert_outcomes(passed=2)