Skip to content

Commit

Permalink
Reenable coverate instrumentation of test files
Browse files Browse the repository at this point in the history
  • Loading branch information
labbati committed Dec 18, 2024
1 parent 073f7f5 commit 4d4cc85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ddtrace/internal/coverage/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ddtrace.internal.coverage.util import collapse_ranges
from ddtrace.internal.logger import get_logger
from ddtrace.internal.module import ModuleWatchdog
from ddtrace.internal.packages import is_ddtrace_pytest_test
from ddtrace.internal.packages import is_user_code
from ddtrace.internal.packages import platlib_path
from ddtrace.internal.packages import platstdlib_path
Expand Down Expand Up @@ -327,7 +328,7 @@ def transform(self, code: CodeType, _module: ModuleType) -> CodeType:
# Don't instrument code from standard library/site packages/etc.
return code

if not is_user_code(code_path):
if not is_user_code(code_path) and not is_ddtrace_pytest_test(code_path):
return code

retval = self.instrument_code(code, _module.__package__ if _module is not None else "")
Expand Down
9 changes: 9 additions & 0 deletions ddtrace/internal/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from functools import singledispatch
import inspect
import logging
from os import environ
from os import fspath # noqa:F401
import sys
import sysconfig
Expand Down Expand Up @@ -272,6 +273,14 @@ def _(path: str) -> bool:
return not (is_stdlib(_path) or is_third_party(_path))


def is_ddtrace_pytest_test(path: Path) -> bool:
"""Return an relatively confident guess about whether the file relates to a pytest test run"""
package = filename_to_package(str(path))
if package is None:
return False
return package.name == "ddtrace" and "PYTEST_CURRENT_TEST" in environ and "/dd-trace-py/tests/" in str(path)


@cached(maxsize=256)
def is_distribution_available(name: str) -> bool:
"""Determine if a distribution is available in the current environment."""
Expand Down

0 comments on commit 4d4cc85

Please sign in to comment.