Skip to content

Commit

Permalink
Remove fixture in favor of test skips
Browse files Browse the repository at this point in the history
  • Loading branch information
lrafeei committed Aug 15, 2023
1 parent 8dd1c1b commit dcb3daf
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions tests/agent_unittests/test_package_version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,10 @@ def patched_pytest_module(monkeypatch):
monkeypatch.delattr(pytest, attr)

yield pytest



@pytest.fixture(scope="function")
def remove_importlib():
if "importlib" not in sys.modules:
return

importlib = sys.modules["importlib"]
del sys.modules["importlib"]
yield
sys.modules["importlib"] = importlib


# This test only works on Python 3.7
@SKIP_IF_IMPORTLIB_METADATA
@pytest.mark.parametrize(
"attr,value,expected_value",
(
Expand All @@ -68,7 +59,7 @@ def remove_importlib():
("version_tuple", [3, 1, "0b2"], "3.1.0b2"),
),
)
def test_get_package_version(attr, value, expected_value, remove_importlib):
def test_get_package_version(attr, value, expected_value):
# There is no file/module here, so we monkeypatch
# pytest instead for our purposes
setattr(pytest, attr, value)
Expand All @@ -77,7 +68,9 @@ def test_get_package_version(attr, value, expected_value, remove_importlib):
delattr(pytest, attr)


def test_skips_version_callables(remove_importlib):
# This test only works on Python 3.7
@SKIP_IF_IMPORTLIB_METADATA
def test_skips_version_callables():
# There is no file/module here, so we monkeypatch
# pytest instead for our purposes
setattr(pytest, "version", lambda x: "1.2.3.4")
Expand All @@ -91,6 +84,8 @@ def test_skips_version_callables(remove_importlib):
delattr(pytest, "version_tuple")


# This test only works on Python 3.7
@SKIP_IF_IMPORTLIB_METADATA
@pytest.mark.parametrize(
"attr,value,expected_value",
(
Expand All @@ -100,7 +95,7 @@ def test_skips_version_callables(remove_importlib):
("version_tuple", [3, 1, "0b2"], (3, 1, "0b2")),
),
)
def test_get_package_version_tuple(attr, value, expected_value, remove_importlib):
def test_get_package_version_tuple(attr, value, expected_value):
# There is no file/module here, so we monkeypatch
# pytest instead for our purposes
setattr(pytest, attr, value)
Expand Down

0 comments on commit dcb3daf

Please sign in to comment.