DataDog / dd-trace-py

Datadog Python APM Client
https://ddtrace.readthedocs.io/
Other
506 stars 397 forks source link

fix(ci_visibility): properly resolve decorated functions for test source file information #9586

Closed romainkomorndatadog closed 1 week ago

romainkomorndatadog commented 2 weeks ago

Fixes an issue where decorated test functions could resolve to the wrong location when certain decorators (eg: @mock.patch) were used.

This also fixes the fact that source file info paths might not always be relative to the current repo root.

The test added in this PR verifies the above by using a variety of decorators as well as executing from the nested_dir directory instead of the git repo root, with the source file info properly showing the path as nested_dir/test_mydecorators.py.

Checklist

Reviewer Checklist

datadog-dd-trace-py-rkomorn[bot] commented 2 weeks ago

Datadog Report

Branch report: romain.komorn/SDTEST-326/make_pytest_source_properly_relative_to_repo Commit report: 8b803fb Test service: dd-trace-py

:white_check_mark: 0 Failed, 176719 Passed, 1217 Skipped, 11h 27m 23.87s Total duration (26m 21.08s time saved)

pr-commenter[bot] commented 2 weeks ago

Benchmarks

Benchmark execution time: 2024-06-26 11:49:08

Comparing candidate commit 0bb75e46ed2f172213b748247c8c66f27dcf6fdc in PR branch romain.komorn/SDTEST-326/make_pytest_source_properly_relative_to_repo with baseline commit 3010fa1b350f12fb0f38272c8e54acd343459053 in branch main.

Found 1 performance improvements and 0 performance regressions! Performance is the same for 220 metrics, 9 unstable metrics.

scenario:otelspan-start

romainkomorndatadog commented 2 weeks ago

Switched to using our more robust and already existing internal undecorated() function, and use item.path (if available) or item.fspath (for pytest<=7.0).

romainkomorndatadog commented 2 weeks ago

Manually tested this with:

github-actions[bot] commented 1 week ago

The backport to 2.7 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.7 2.7
# Navigate to the new working tree
cd .worktrees/backport-2.7
# Create a new branch
git switch --create backport-9586-to-2.7
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 203e89489f1e698a127317dc57b01e9d6467e859
# Push it to GitHub
git push --set-upstream origin backport-9586-to-2.7
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.7

Then, create a pull request where the base branch is 2.7 and the compare/head branch is backport-9586-to-2.7.

github-actions[bot] commented 1 week ago

The backport to 2.8 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.8 2.8
# Navigate to the new working tree
cd .worktrees/backport-2.8
# Create a new branch
git switch --create backport-9586-to-2.8
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 203e89489f1e698a127317dc57b01e9d6467e859
# Push it to GitHub
git push --set-upstream origin backport-9586-to-2.8
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.8

Then, create a pull request where the base branch is 2.8 and the compare/head branch is backport-9586-to-2.8.

github-actions[bot] commented 1 week ago

The backport to 2.9 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.9 2.9
# Navigate to the new working tree
cd .worktrees/backport-2.9
# Create a new branch
git switch --create backport-9586-to-2.9
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 203e89489f1e698a127317dc57b01e9d6467e859
# Push it to GitHub
git push --set-upstream origin backport-9586-to-2.9
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.9

Then, create a pull request where the base branch is 2.9 and the compare/head branch is backport-9586-to-2.9.