From c4a0d53e4757a3dd320759aac44819fa79835090 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 13 Sep 2024 16:25:18 +0200 Subject: [PATCH] opentelemetry-instrumentation: fix another test --- .../tests/test_dependencies.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/opentelemetry-instrumentation/tests/test_dependencies.py b/opentelemetry-instrumentation/tests/test_dependencies.py index 7448dec4e0..bdee0f6f01 100644 --- a/opentelemetry-instrumentation/tests/test_dependencies.py +++ b/opentelemetry-instrumentation/tests/test_dependencies.py @@ -14,9 +14,8 @@ # 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, @@ -24,6 +23,7 @@ get_dist_dependency_conflicts, ) from opentelemetry.test.test_base import TestBase +from opentelemetry.util._importlib_metadata import Distribution class TestDependencyConflicts(TestBase): @@ -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"', )