Skip to content

Commit cbd0597

Browse files
fix(ci_visibility): do not use is_user_code [backport 3.15] (#14810)
Backport 7cd4d9c from #14794 to 3.15. ## Description Currently, in Test Impact Analysis code coverage, we use `is_user_code()` to decide whether to instrument a module. This function was conceived for use in non-CI contexts where user code may be installed in site-packages like external dependencies. This is not necessary in Test Optimization, where we only want to cover code inside the current repo (TIA only works with filenames that are relative to the repo root, and we already set the repo root as the include path of `ModuleCodeCollector`). Removing this check also resolves a bug where test packages are incorrectly detected as third-party if a third-party package contains files under `test/*` or `tests/*` that get installed at site-packages level (`sumy` and `sendgrid` do this, for instance). ## Testing Unit tests + manual testing in dogweb. ## Risks Potentially covering more code than expected. Should not be an issue because we already exclude site-packages and similar [here](https://github.com/DataDog/dd-trace-py/blob/vitor-de-araujo%2FSDTEST-2747%2Fcoverage-third-party/ddtrace/internal/coverage/code.py#L53). ## Additional Notes None. Co-authored-by: Vítor De Araújo <[email protected]>
1 parent f32c72b commit cbd0597

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

ddtrace/internal/coverage/code.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from ddtrace.internal.coverage.util import collapse_ranges
1515
from ddtrace.internal.logger import get_logger
1616
from ddtrace.internal.module import ModuleWatchdog
17-
from ddtrace.internal.packages import is_user_code
1817
from ddtrace.internal.packages import platlib_path
1918
from ddtrace.internal.packages import platstdlib_path
2019
from ddtrace.internal.packages import purelib_path
@@ -327,9 +326,6 @@ def transform(self, code: CodeType, _module: ModuleType) -> CodeType:
327326
# Don't instrument code from standard library/site packages/etc.
328327
return code
329328

330-
if not is_user_code(code_path):
331-
return code
332-
333329
retval = self.instrument_code(code, _module.__package__ if _module is not None else "")
334330

335331
if self._collect_import_coverage:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
CI Visibility: This fix resolves an issue where tests would be incorrectly detected as third-party code if a
5+
third-party package containing a folder with the same name as the tests folder was installed. For instance, the
6+
``sumy`` package installs files under ``tests/*`` in ``site-packages``, and this would cause any modules under
7+
``tests.*`` to be considered third-party.

0 commit comments

Comments
 (0)