Skip to content

Commit

Permalink
opentelemetry-instrumentation: fix another test
Browse files Browse the repository at this point in the history
  • Loading branch information
xrmx committed Sep 13, 2024
1 parent 4abf72d commit c4a0d53
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions opentelemetry-instrumentation/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

# pylint: disable=protected-access

from opentelemetry.util._importlib_metadata import Distribution, requires
from packaging.requirements import Requirement
import pytest
from packaging.requirements import Requirement

from opentelemetry.instrumentation.dependencies import (
DependencyConflict,
get_dependency_conflicts,
get_dist_dependency_conflicts,
)
from opentelemetry.test.test_base import TestBase
from opentelemetry.util._importlib_metadata import Distribution


class TestDependencyConflicts(TestBase):
Expand Down Expand Up @@ -66,20 +66,23 @@ def test_get_dependency_conflicts_mismatched_version(self):
)

def test_get_dist_dependency_conflicts(self):
def mock_requires(extras=()):
if "instruments" in extras:
return requires(
'test-pkg ~= 1.0; extra == "instruments"'
)
return []
class MockDistribution(Distribution):
def locate_file(self, path):
pass

def read_text(self, filename):
pass

@property
def requires(self):
return ['test-pkg ~= 1.0; extra == "instruments"']

dist = Distribution()
dist.requires = mock_requires
dist = MockDistribution()

conflict = get_dist_dependency_conflicts(dist)
self.assertTrue(conflict is not None)
self.assertTrue(isinstance(conflict, DependencyConflict))
self.assertEqual(
str(conflict),
'DependencyConflict: requested: "test-pkg~=1.0" but found: "None"',
'DependencyConflict: requested: "test-pkg~=1.0; extra == "instruments"" but found: "None"',
)

0 comments on commit c4a0d53

Please sign in to comment.