Skip to content

Commit

Permalink
Make tests more comprehensive
Browse files Browse the repository at this point in the history
  • Loading branch information
lrafeei committed Nov 25, 2024
1 parent 10d5c21 commit f1b6279
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
2 changes: 0 additions & 2 deletions newrelic/common/package_version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ def _get_package_version(name):
try:
version = getattr(module, attr, None)

# In certain cases like importlib_metadata.version, version is a callable
# function.
# Some frameworks (such as `pypdfium2`) may use a class
# property to define the version. Because class properties
# are not callable we need to check if the result is
Expand Down
12 changes: 2 additions & 10 deletions tests/agent_unittests/test_package_version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def test_version_caching(monkeypatch):
assert version not in NULL_VERSIONS, version


@SKIP_IF_NOT_IMPORTLIB_METADATA
def test_version_as_class_property(monkeypatch):
# There is no file/module here, so we monkeypatch
# pytest instead for our purposes
Expand All @@ -162,18 +161,14 @@ def version(self):
return "1.2.3"

monkeypatch.setattr(pytest, "version", FakeModule.version, raising=False)
monkeypatch.setattr(
sys.modules["importlib"].metadata, "version", lambda x: "1.2.3", raising=False # pylint: disable=E1101
)

version = get_package_version("pytest")
assert version == "1.2.3"
assert version not in NULL_VERSIONS, version


# This test checks to see if the version is a property of the class
# but also checks to see if the something like version.version_tuple
# has been exported as a tuple.
@SKIP_IF_NOT_IMPORTLIB_METADATA
def test_version_as_class_property_and_version_tuple(monkeypatch):
# There is no file/module here, so we monkeypatch
# pytest instead for our purposes
Expand All @@ -184,9 +179,6 @@ def version(self):

monkeypatch.setattr(pytest, "version", FakeModule.version, raising=False)
monkeypatch.setattr(pytest, "version_tuple", (1, 2, 3), raising=False)
monkeypatch.setattr(
sys.modules["importlib"].metadata, "version", lambda x: "1.2.3", raising=False # pylint: disable=E1101
)

version = get_package_version("pytest")
assert version == "1.2.3"
assert version not in NULL_VERSIONS, version

0 comments on commit f1b6279

Please sign in to comment.