Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve source roots with Pytest output #10165

Merged
merged 9 commits into from Jul 7, 2020

Conversation

Eric-Arellano
Copy link
Contributor

Before:

pants/util/filtering_test.py ......                           [ 10%]
pants/util/frozendict_test.py ...............                 [ 36%]
pants/util/ordered_set_test.py .............................. [ 89%]
......                                                        [100%]

After

src/python/pants/util/filtering_test.py ......                           [ 10%]
src/python/pants/util/frozendict_test.py ...............                 [ 36%]
src/python/pants/util/ordered_set_test.py .............................. [ 89%]
......                                                                   [100%]

This also allows us to remove the custom Pants Coverage plugin, which greatly simplifies the code path and improves performance (8s to run coverage on pants_test/util:objects before, and only 4 seconds after). This does introduce a regression that we no longer report on files never touched by the test, but this was a similar issue before that we already had to solve. We will fix this problem as part of #10064.

[ci skip-jvm-tests]
[ci skip-rust-tests]

# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]
[ci skip-rust-tests]
@@ -251,9 +245,10 @@ async def run_python_test(
if use_coverage:
output_files.append(".coverage")

# We explicitly add the CWD to the PEX runtime sys.path. Some pytest plugins
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the django example will still work, but if not I'll fix it, so this is fine for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thank you! If it turns out this breaks, it would be good to add a unit test.

Eric-Arellano and others added 8 commits June 25, 2020 14:21
# Delete this line to force CI to run Clippy and the Rust tests.
[ci skip-rust-tests]
# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]
…-strip

[ci skip-rust-tests]
[ci skip-jvm-tests]
…how up in the result

We must use `python_sources.py` to properly inject any missing `__init__.py` files at the report time. This allows us to remove `--ignore-errors`, which is good to make it more likely for us to discover issues with the project.

[ci skip-rust-tests]

# Conflicts:
#	src/python/pants/backend/python/rules/coverage.py
#	src/python/pants/backend/python/rules/coverage_integration_test.py
# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
…-strip

[ci skip-rust-tests]
# Conflicts:
#	src/python/pants/backend/python/rules/coverage.py
#	src/python/pants/backend/python/rules/coverage_plugin/BUILD
#	src/python/pants/backend/python/rules/pytest_runner_integration_test.py
… the instance of pants that we are testing.

# Rust tests will be skipped. Delete if not intended.
[ci skip-rust-tests]
@stuhood stuhood merged commit 85b0fd2 into pantsbuild:master Jul 7, 2020
@Eric-Arellano Eric-Arellano deleted the pytest-dont-strip branch October 9, 2020 18:11
@jsirois
Copy link
Member

jsirois commented Jul 31, 2021

This does introduce a regression that we no longer report on files never touched by the test, but this was a similar issue before that we already had to solve. We will fix this problem as part of #10064.

The issue was never fixed with #10064 (IOW the random.py file is still not expected in the test_coverage test). I have a fix though as part of #12390.

jsirois added a commit to jsirois/pants that referenced this pull request Jul 31, 2021
Previously, the combination of collecting relative_paths and passing
`--cov=.` to pytest-cov could lead to coverage collection of invalid
paths (namely: "(builtin)") which would cause coverage report generation
to fail. Fix this by restricting coverage to the source roots of the
code under test. This also solves a regression introduced by pantsbuild#10165.

Fixes pantsbuild#12390

[ci skip-rust]

[ci skip-build-wheels]
jsirois added a commit that referenced this pull request Jul 31, 2021
Previously, the combination of collecting relative_paths and passing
`--cov=.` to pytest-cov could lead to coverage collection of invalid
paths (namely: "(builtin)") which would cause coverage report generation
to fail. Fix this by restricting coverage to the source roots of the
code under test. This also solves a regression introduced by #10165.

Fixes #12390
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants