|
| 1 | +import sys |
| 2 | + |
1 | 3 | import pytest
|
2 | 4 |
|
3 | 5 | from ddtrace.debugging._function.discovery import FunctionDiscovery
|
4 | 6 | from ddtrace.internal.module import ModuleWatchdog
|
5 | 7 | import tests.submod.stuff as stuff
|
6 | 8 |
|
7 | 9 |
|
| 10 | +@pytest.fixture |
| 11 | +def no_pytest_loader(): |
| 12 | + from _pytest.assertion.rewrite import AssertionRewritingHook |
| 13 | + |
| 14 | + i = next(i for i, hook in enumerate(sys.meta_path) if isinstance(hook, AssertionRewritingHook)) |
| 15 | + pytest_loader = sys.meta_path.pop(i) |
| 16 | + |
| 17 | + try: |
| 18 | + yield |
| 19 | + finally: |
| 20 | + sys.meta_path.insert(i, pytest_loader) |
| 21 | + |
| 22 | + |
8 | 23 | @pytest.fixture
|
9 | 24 | def stuff_discovery():
|
10 | 25 | return FunctionDiscovery.from_module(stuff)
|
@@ -124,18 +139,20 @@ def test_property_non_function_getter(stuff_discovery):
|
124 | 139 | stuff_discovery.by_name("PropertyStuff.foo")
|
125 | 140 |
|
126 | 141 |
|
127 |
| -def test_custom_decorated_stuff(): |
| 142 | +def test_custom_decorated_stuff(no_pytest_loader): |
128 | 143 | class DiscoveryModuleWatchdog(ModuleWatchdog):
|
129 | 144 | def transform(self, code, module):
|
130 | 145 | return FunctionDiscovery.transformer(code, module)
|
131 | 146 |
|
132 | 147 | DiscoveryModuleWatchdog.install()
|
133 | 148 |
|
134 |
| - import tests.submod.custom_decorated_stuff as custom_decorated_stuff |
| 149 | + try: |
| 150 | + import tests.submod.custom_decorated_stuff as custom_decorated_stuff |
135 | 151 |
|
136 |
| - fd = FunctionDiscovery.from_module(custom_decorated_stuff) |
| 152 | + fd = FunctionDiscovery.from_module(custom_decorated_stuff) |
137 | 153 |
|
138 |
| - (home,) = fd.at_line(17) |
139 |
| - assert home.__qualname__ == "home" |
| 154 | + (home,) = fd.at_line(17) |
| 155 | + assert home.__qualname__ == "home" |
140 | 156 |
|
141 |
| - DiscoveryModuleWatchdog.uninstall() |
| 157 | + finally: |
| 158 | + DiscoveryModuleWatchdog.uninstall() |
0 commit comments