Skip to content

Commit 0dd5022

Browse files
authored
ci(internal): make flaky wrapping test a subprocess test (#13797)
## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [ ] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent 5fb2a8a commit 0dd5022

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

tests/internal/test_wrapping.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
from contextlib import asynccontextmanager
3-
import gc
43
import inspect
54
import sys
65
from types import CoroutineType
@@ -808,7 +807,43 @@ async def fibonacci(n):
808807
assert set(values) == {(n, n) for n in range(0, N)}
809808

810809

810+
# DEV: Since this test relies on `gc`, run this test as a subprocess and avoid over-importing
811+
# too many modules to avoid outside impact on `gc` causing flakiness
812+
@pytest.mark.subprocess()
811813
def test_wrapping_context_method_leaks():
814+
import gc
815+
816+
from ddtrace.internal.wrapping.context import WrappingContext
817+
818+
NOTSET = object()
819+
820+
# DEV: Redefine this module level class to avoid importing `tests.internal.test_wrapping`
821+
# to help reduce flakiness caused by outside impact on `gc`
822+
class DummyWrappingContext(WrappingContext):
823+
def __init__(self, f):
824+
super().__init__(f)
825+
826+
self.entered = False
827+
self.exited = False
828+
self.return_value = NOTSET
829+
self.exc_info = None
830+
self.frame = None
831+
832+
def __enter__(self):
833+
self.entered = True
834+
self.frame = self.__frame__
835+
return super().__enter__()
836+
837+
def __exit__(self, exc_type, exc_value, traceback):
838+
self.exited = True
839+
if exc_value is not None:
840+
self.exc_info = (exc_type, exc_value, traceback)
841+
super().__exit__(exc_type, exc_value, traceback)
842+
843+
def __return__(self, value):
844+
self.return_value = value
845+
return super().__return__(value)
846+
812847
def foo():
813848
return 42
814849

0 commit comments

Comments
 (0)