echoing-manchester-70122
06/09/2020, 7:22 PM[test.pytest]
coverage=auto
hundreds-father-404
06/09/2020, 7:30 PMechoing-manchester-70122
06/09/2020, 7:30 PM# <https://jira.pinadmin.com/browse/SRE-4755> - all pytest config can probably be set back to defaults once we remove py2.7 support
[pytest]
version: pytest>=4.6.6,<4.7
pytest_plugins: +["setuptools<45; python_version < '3'","configparser==4.0.2; python_version < '3'","zipp<2; python_version < '3'","importlib-metadata<1.6; python_version < '3'"]
[test.pytest]
coverage=auto
echoing-manchester-70122
06/09/2020, 7:30 PMechoing-manchester-70122
06/09/2020, 7:31 PMechoing-manchester-70122
06/09/2020, 7:31 PM[pytest]
timeout_requirements: pytest-timeout==1.2.0
cov_requirements: pytest-cov==2.4.0
[test.pytest]
coverage=auto
hundreds-father-404
06/09/2020, 7:32 PM./pants options | grep pytest
to double check that it’s resolving the option correctlyechoing-manchester-70122
06/09/2020, 7:33 PM$ ./pants options |grep pytest
Scrubbed PYTHONPATH=/Users/amckenna/code/python-commons/src/main/python from the environment.
pytest.cov_requirements = pytest-cov>=2.8.1,<3 (from HARDCODED)
pytest.pytest_plugins = ['pytest-timeout>=1.3.3,<1.4', 'pytest-cov>=2.8.1,<3', "unittest2>=1.1.0 ; python_version<'3'", "more-itertools<6.0.0 ; python_version<'3'", "setuptools<45; python_version < '3'", "configparser==4.0.2; python_version < '3'", "zipp<2; python_version < '3'", "importlib-metadata<1.6; python_version < '3'"] (from CONFIG in pants.ini)
pytest.requirements = pytest>=4.6.6,<4.7 (from HARDCODED)
pytest.timeout_requirements = pytest-timeout>=1.3.3,<1.4 (from HARDCODED)
pytest.unittest2_requirements = unittest2>=1.1.0 ; python_version<'3' (from HARDCODED)
pytest.version = pytest>=4.6.6,<4.7 (from HARDCODED)
test.pytest.chroot = False (from HARDCODED)
test.pytest.coverage = auto (from CONFIG in pants.ini)
test.pytest.coverage_include_test_sources = False (from HARDCODED)
test.pytest.coverage_output_dir = None (from NONE)
test.pytest.coverage_reports = ['xml', 'html'] (from HARDCODED)
test.pytest.extra_pythonpath = [] (from NONE)
test.pytest.fast = True (from HARDCODED)
test.pytest.junit_xml_dir = None (from NONE)
test.pytest.passthrough_args = [] (from NONE)
test.pytest.profile = None (from NONE)
test.pytest.skip = False (from HARDCODED)
test.pytest.test_shard = None (from NONE)
test.pytest.timeout_default = None (from NONE)
test.pytest.timeout_maximum = None (from NONE)
test.pytest.timeout_terminate_wait = 10 (from HARDCODED)
test.pytest.timeouts = True (from HARDCODED)
hundreds-father-404
06/09/2020, 7:36 PMpytest-cov
still shows up. Good. The coverage options all look correct too
This has never been working in 1.23 for you? We’ve barely touched that codepath the past few months, so I’m trying to pin down what would be causing the issuehundreds-father-404
06/09/2020, 7:36 PMechoing-manchester-70122
06/09/2020, 7:36 PMechoing-manchester-70122
06/09/2020, 7:36 PMechoing-manchester-70122
06/09/2020, 7:36 PM===== 17 passed, 5 warnings in 2.78 seconds ======
12:34:26 00:40 [coverage-html]
12:34:28 00:42 [coverage-xml]
src/test/python/.../devapp_tool ..... SUCCESS
Waiting for background workers to finish.
12:34:29 00:43 [complete]
SUCCESS
hundreds-father-404
06/09/2020, 7:40 PMcoverage_output_dir
in [test.pytest]
? You can explicitly set to 'dist/coverage'
, for exampleechoing-manchester-70122
06/09/2020, 7:43 PMechoing-manchester-70122
06/09/2020, 7:43 PMhundreds-father-404
06/09/2020, 8:59 PMpants.ini
you sent. Anything of note with your python_tests
target, e.g. if it explicitly sets the coverage
field? Is the test target in the same folder as the src code?echoing-manchester-70122
06/09/2020, 8:59 PMechoing-manchester-70122
06/09/2020, 9:00 PM$ grep -i coverage pants pants.ini
pants.ini:coverage=auto
pants.ini:coverage_output_dir=dist/coverage
hundreds-father-404
06/09/2020, 9:00 PM./pants test
or ./pants test path/to:test_target
?echoing-manchester-70122
06/09/2020, 9:00 PMhundreds-father-404
06/09/2020, 9:01 PMpython_tests
target you’re specifying live in the same folder as the src
code? Or you’re setting the coverage
field in the BUILD file?echoing-manchester-70122
06/09/2020, 9:06 PMimportant-librarian-62877
06/09/2020, 10:57 PMhundreds-father-404
06/09/2020, 11:05 PMNo .coverage file was found! Skipping coverage reporting.
Does that look familiar?hundreds-father-404
06/09/2020, 11:19 PMimportant-librarian-62877
06/09/2020, 11:24 PM[coverage-<type>]
tag.hundreds-father-404
06/09/2020, 11:36 PMauto
is limited / doesn’t always work. Try setting the field coverage=['helloworld.util.demo']
in your python_tests
target, but with the module that you expect to cover. Lmk if that works to get data generated
I suspect that when it worked on 1.16, you were running against a different target where auto
did happen to work. Now you’re running on a target that can’t be inferred, for whatever reason. In other words, I suspect Pants hasn’t changed, but rather the command being run has changedhundreds-father-404
06/09/2020, 11:55 PMauto
https://github.com/Eric-Arellano/coverage-debug/pull/1
If auto
is not working, I suspect the issue is that the tests are not in the same folder as the src
code, e.g. having src/python
and tests/python
folders. In that case, you’d specify the coverage
field in each python_tests
targetimportant-librarian-62877
06/10/2020, 12:01 AMcoverage
field?echoing-manchester-70122
06/10/2020, 12:02 AMechoing-manchester-70122
06/10/2020, 12:02 AMechoing-manchester-70122
06/10/2020, 12:03 AMenough-analyst-54434
06/10/2020, 12:04 AM./pants roots
?echoing-manchester-70122
06/10/2020, 12:05 AM$ ./pants roots
Scrubbed PYTHONPATH=/Users/amckenna/code/python-commons/src/main/python from the environment.
3rdparty/python: python
src/__pycache__: __pycache__
src/main: *
src/main/attic: attic
src/main/config: config
src/main/python: python
src/main/thrift: thrift
src/test: *
src/test/__pycache__: __pycache__
src/test/attic: attic
src/test/python: python
enough-analyst-54434
06/10/2020, 12:08 AMcoverage-html and coverage-xml are just blankDo you mean the generated index.html and coverage.xml under dist/coverage/... are blank? Or they just don't even exist?
echoing-manchester-70122
06/10/2020, 12:09 AMechoing-manchester-70122
06/10/2020, 12:09 AMenough-analyst-54434
06/10/2020, 12:09 AMenough-analyst-54434
06/10/2020, 12:09 AMenough-analyst-54434
06/10/2020, 12:10 AMenough-analyst-54434
06/10/2020, 12:11 AM17:10:35 00:06 [coverage-report]
Name Stmts Miss Branch BrPart Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/jsirois/dev/Eric-Arellano/jsirois-coverage-debug/.pants.d/pyprep/sources/7f6099ca983f89070bc723af80d653cdf20ba5d3/pkg/__init__.py 1 0 0 0 100%
src/python/pkg/demo.py 2 0 0 0 100%
src/python/pkg/demo_test.py 3 0 0 0 100%
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL 6 0 0 0 100%
17:10:36 00:07 [coverage-html]
17:10:36 00:07 [coverage-xml]
src/python/pkg:tests ..... SUCCESS
enough-analyst-54434
06/10/2020, 12:11 AM[coverage-report]
console output section. Is that correct?hundreds-father-404
06/10/2020, 12:12 AMIs there documentation for that coverage field?On Pants 1.27+,
./pants target-types --details=python_tests
. On older, ./pants targets --details=python_tests
. (We’re also soon working on adding docs to the new website about the v2 engine implementation, which is quite similar)echoing-manchester-70122
06/10/2020, 12:12 AMenough-analyst-54434
06/10/2020, 12:13 AMechoing-manchester-70122
06/10/2020, 12:14 AMenough-analyst-54434
06/10/2020, 12:15 AMechoing-manchester-70122
06/10/2020, 12:15 AMenough-analyst-54434
06/10/2020, 12:15 AMenough-analyst-54434
06/10/2020, 12:16 AMenough-analyst-54434
06/10/2020, 12:17 AMechoing-manchester-70122
06/10/2020, 12:18 AMechoing-manchester-70122
06/10/2020, 12:18 AMenough-analyst-54434
06/10/2020, 12:20 AMechoing-manchester-70122
06/10/2020, 12:20 AMenough-analyst-54434
06/10/2020, 12:20 AMenough-analyst-54434
06/10/2020, 12:20 AMenough-analyst-54434
06/10/2020, 12:21 AMhundreds-father-404
06/10/2020, 12:22 AM./pants
script lets you use without using an older version of the bash script, and I was being a little lazy.enough-analyst-54434
06/10/2020, 12:24 AMenough-analyst-54434
06/10/2020, 12:24 AMhundreds-father-404
06/10/2020, 12:26 AMenough-analyst-54434
06/10/2020, 12:27 AMechoing-manchester-70122
06/10/2020, 12:27 AMenough-analyst-54434
06/10/2020, 12:40 AM$ git diff src/python/pants/backend/python/tasks/pytest_run.py
diff --git a/src/python/pants/backend/python/tasks/pytest_run.py b/src/python/pants/backend/python/tasks/pytest_run.py
index fa279e1a0..0f9b96408 100644
--- a/src/python/pants/backend/python/tasks/pytest_run.py
+++ b/src/python/pants/backend/python/tasks/pytest_run.py
@@ -137,7 +137,7 @@ class PytestRun(ChrootedTestRunnerTaskMixin, Task):
register(
"--coverage-reports",
fingerprint=True,
- choices=("xml", "html"),
+ choices=("xml", "html", "console"),
type=list,
member_type=str,
default=("xml", "html"),
@@ -432,6 +432,8 @@ class PytestRun(ChrootedTestRunnerTaskMixin, Task):
else:
coverage_workdir = workdirs.coverage_path
coverage_reports = self.get_options().coverage_reports
+ if "console" in coverage_reports:
+ coverage_run('report', ['-i', '--rcfile', coverage_rc])
if "html" in coverage_reports:
coverage_run(
"html", ["-i", "--rcfile", coverage_rc, "-d", coverage_workdir]
enough-analyst-54434
06/10/2020, 12:42 AMimportant-librarian-62877
06/10/2020, 12:46 AMhundreds-father-404
06/10/2020, 12:48 AMsrc/python
and tests/python
source roots to putting everything into src/python
. When tests are in the same folder as the src code, auto
should work. (We also like being able to easily see which files have tests and which don’t)enough-analyst-54434
06/10/2020, 12:59 AMimportant-librarian-62877
06/10/2020, 1:10 AMtoplevel/module/module/*.py
, toplevel/module/tests_module/*.py
, where toplevel
can be libraries, services, etc. There can also be subdirectories under the second level module
. I'm not really seeing a simple way to set up coverage for a case like that 🙁hundreds-father-404
06/10/2020, 1:21 AMimportant-librarian-62877
06/10/2020, 1:39 AMhundreds-father-404
06/10/2020, 1:41 AMcoverage
field on every targetenough-analyst-54434
06/10/2020, 11:18 PM--test-pytest-coverage-reports=console
on the CLI or else add this to the list of reports printed by default either in ~/.pants.rc (for just you personally) or pants.ini (for the whole repo):
[test.pytest]
coverage_reports: +["console"]
echoing-manchester-70122
06/10/2020, 11:20 PMimportant-librarian-62877
06/11/2020, 12:42 AMlist
and the --test-pytest-coverage
option @enough-analyst-54434 mentioned to accomplish coverage for our situation. Talked with the team about moving the source and test files together and they were against it. I will write up a ticket with our situation, but again, it's definitely just a nice to have.hundreds-father-404
06/11/2020, 12:44 AMimportant-librarian-62877
06/11/2020, 1:31 AMhundreds-father-404
06/17/2020, 1:52 AMcoverage
field, you can use a looser module. That is, you can use any of project.util.dirutil
, project.util
, or project
.
If you use project
, then Coverage will calculate the coverage for any module that starts with project
, and so on.
I’ll be documenting this all this week too. (Tracked by https://github.com/pantsbuild/pants/issues/10064)jolly-midnight-72759
06/25/2020, 9:15 PMhundreds-father-404
06/25/2020, 9:20 PMcoverage
field is a little weird to get right.
We redesigned it in 1.30.0 and are putting final polish on how coverage works in 2.0.0. See the PR description of https://github.com/pantsbuild/pants/pull/10100 for how it works now