Skip to content

Commit cb941b5

Browse files
committed
opentelemetry-instrumentation: fix another test
1 parent 965a69d commit cb941b5

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

opentelemetry-instrumentation/tests/test_dependencies.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
# pylint: disable=protected-access
1616

17-
from opentelemetry.util._importlib_metadata import Distribution, requires
18-
from packaging.requirements import Requirement
1917
import pytest
18+
from packaging.requirements import Requirement
2019

2120
from opentelemetry.instrumentation.dependencies import (
2221
DependencyConflict,
2322
get_dependency_conflicts,
2423
get_dist_dependency_conflicts,
2524
)
2625
from opentelemetry.test.test_base import TestBase
26+
from opentelemetry.util._importlib_metadata import Distribution
2727

2828

2929
class TestDependencyConflicts(TestBase):
@@ -66,20 +66,23 @@ def test_get_dependency_conflicts_mismatched_version(self):
6666
)
6767

6868
def test_get_dist_dependency_conflicts(self):
69-
def mock_requires(extras=()):
70-
if "instruments" in extras:
71-
return requires(
72-
'test-pkg ~= 1.0; extra == "instruments"'
73-
)
74-
return []
69+
class MockDistribution(Distribution):
70+
def locate_file(self, path):
71+
pass
72+
73+
def read_text(self, filename):
74+
pass
75+
76+
@property
77+
def requires(self):
78+
return ['test-pkg ~= 1.0; extra == "instruments"']
7579

76-
dist = Distribution()
77-
dist.requires = mock_requires
80+
dist = MockDistribution()
7881

7982
conflict = get_dist_dependency_conflicts(dist)
8083
self.assertTrue(conflict is not None)
8184
self.assertTrue(isinstance(conflict, DependencyConflict))
8285
self.assertEqual(
8386
str(conflict),
84-
'DependencyConflict: requested: "test-pkg~=1.0" but found: "None"',
87+
'DependencyConflict: requested: "test-pkg~=1.0; extra == "instruments"" but found: "None"',
8588
)

0 commit comments

Comments
 (0)