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

pytest: use output_files for junit XML generation option #10136

Merged
merged 4 commits into from Jun 24, 2020

Conversation

tdyas
Copy link
Contributor

@tdyas tdyas commented Jun 23, 2020

Problem

When running pytest with JUnit XML generation enabled, the Pants pytest_runner uses output_directories instead of output_files to make the output file known to the process executor. This works fine with local execution but breaks with remote execution because RE servers can skip output_directories that are not in fact directories.

This issue manifests as errors like this:

$ ./pants --pytest-junit-xml-dir=dist/test-results [remote-config options] test XXX
05:07:26.01 [INFO] Completed: Run Pytest for XXX
05:07:26.02 [WARN] Failed to generate JUnit XML data for XXX.
05:07:26.02 [INFO] Tests failed: XXX
𐄂 XXX
ERROR: --junitxml must be a filename, given: XXX.xml

Solution

Use output_files instead for the JUnit XML generation file.

Result

The test runs and JUnit XML is properly generated and written to the local filesystem.

@Eric-Arellano
Copy link
Contributor

Thanks Tom!

It’d be good for us to test Junit XML. You can mostly copy the test_success method, minus setting up the flag + inspecting the XML file in the TestResult. I’m happy to help tomorrow with this.

@asherf
Copy link
Member

asherf commented Jun 23, 2020

This issue is a problem long term, we basically have an API (output_directories) that works locally but won't work with remote execution, which is bad.
this needs to be solved at the infra level somehow or we just need to deprecate the API that is not compatible with RE.

@tdyas
Copy link
Contributor Author

tdyas commented Jun 23, 2020

this needs to be solved at the infra level somehow or we just need to deprecate the API that is not compatible with RE.

REv2 is what actually defines output_files and output_directories. REv2.1 deprecates those options in favor of an output_paths attribute given the issues (as Pants encountered here) with having to differentiate between files and directories in the earlier API versions.

We should probably have the local execution API print a warning (or maybe even error out) if a file ends up in output_directories or a directory ends up in output_files. That would flag the issue earlier.

assert file.path.startswith("dist/test-results")
assert b"pants_test.test_good" in file.content

@pytest.mark.skip(reason="https://github.com/pantsbuild/pants/issues/10141")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is skipped as per discussion with @Eric-Arellano who will fix as per #10141.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thank you, Tom!

assert "test_good.py ." in result.stdout
assert result.xml_results is not None

files: FilesContent = self.request_single_product(FilesContent, result.xml_results)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the type hint is necessary. MyPy should be able to refer the type. I can fix this in a followup, though.

Suggested change
files: FilesContent = self.request_single_product(FilesContent, result.xml_results)
files = self.request_single_product(FilesContent, result.xml_results)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove.

@tdyas
Copy link
Contributor Author

tdyas commented Jun 23, 2020

@Eric-Arellano: I have some additional testing to do this afternoon, will let you know when this is ready. I'm still testing the coverage-related change against build.toolchain.com

@Eric-Arellano
Copy link
Contributor

@tdyas
Copy link
Contributor Author

tdyas commented Jun 23, 2020

Coverage passed remotely:

23:33:01.84 [INFO] Completed: Building coverage.pex with 1 requirement: coverage>=5.0.3,<5.1
23:33:03.85 [INFO] Completed: Generate Pytest report coverage report.

Name                                                                  Stmts   Miss Branch BrPart  Cover
-------------------------------------------------------------------------------------------------------
XXX.py                                          12     12      6      0     0%
[lots of stuff cut]
.
.
.

@tdyas tdyas force-pushed the use_output_files_for_junit_xml branch from ed655d5 to 9addeda Compare June 24, 2020 01:47
@Eric-Arellano Eric-Arellano added this to the 1.30.x milestone Jun 24, 2020
@Eric-Arellano
Copy link
Contributor

Thanks again, Tom!

@Eric-Arellano Eric-Arellano merged commit 396ec64 into pantsbuild:master Jun 24, 2020
stuhood pushed a commit to stuhood/pants that referenced this pull request Jul 11, 2020
…antsbuild#10136)

When running pytest with JUnit XML generation enabled, the Pants pytest_runner [uses `output_directories` instead of `output_files` to make the output file known to the process executor](https://github.com/pantsbuild/pants/blob/master/src/python/pants/backend/python/rules/pytest_runner.py#L237-L245). This works fine with local execution but breaks with remote execution because RE servers can skip `output_directories` that are not in fact directories.

This issue manifests as errors like this:

```
$ ./pants --pytest-junit-xml-dir=dist/test-results [remote-config options] test XXX
05:07:26.01 [INFO] Completed: Run Pytest for XXX
05:07:26.02 [WARN] Failed to generate JUnit XML data for XXX.
05:07:26.02 [INFO] Tests failed: XXX
𐄂 XXX
ERROR: --junitxml must be a filename, given: XXX.xml
```

Use `output_files` instead for the JUnit XML generation file.

The test runs and JUnit XML is properly generated and written to the local filesystem.
stuhood pushed a commit to stuhood/pants that referenced this pull request Jul 13, 2020
…antsbuild#10136)

When running pytest with JUnit XML generation enabled, the Pants pytest_runner [uses `output_directories` instead of `output_files` to make the output file known to the process executor](https://github.com/pantsbuild/pants/blob/master/src/python/pants/backend/python/rules/pytest_runner.py#L237-L245). This works fine with local execution but breaks with remote execution because RE servers can skip `output_directories` that are not in fact directories.

This issue manifests as errors like this:

```
$ ./pants --pytest-junit-xml-dir=dist/test-results [remote-config options] test XXX
05:07:26.01 [INFO] Completed: Run Pytest for XXX
05:07:26.02 [WARN] Failed to generate JUnit XML data for XXX.
05:07:26.02 [INFO] Tests failed: XXX
𐄂 XXX
ERROR: --junitxml must be a filename, given: XXX.xml
```

Use `output_files` instead for the JUnit XML generation file.

The test runs and JUnit XML is properly generated and written to the local filesystem.
stuhood pushed a commit to stuhood/pants that referenced this pull request Jul 14, 2020
…antsbuild#10136)

When running pytest with JUnit XML generation enabled, the Pants pytest_runner [uses `output_directories` instead of `output_files` to make the output file known to the process executor](https://github.com/pantsbuild/pants/blob/master/src/python/pants/backend/python/rules/pytest_runner.py#L237-L245). This works fine with local execution but breaks with remote execution because RE servers can skip `output_directories` that are not in fact directories.

This issue manifests as errors like this:

```
$ ./pants --pytest-junit-xml-dir=dist/test-results [remote-config options] test XXX
05:07:26.01 [INFO] Completed: Run Pytest for XXX
05:07:26.02 [WARN] Failed to generate JUnit XML data for XXX.
05:07:26.02 [INFO] Tests failed: XXX
𐄂 XXX
ERROR: --junitxml must be a filename, given: XXX.xml
```

Use `output_files` instead for the JUnit XML generation file.

The test runs and JUnit XML is properly generated and written to the local filesystem.
stuhood added a commit that referenced this pull request Jul 14, 2020
…herrypick of #10136) (#10324)

When running pytest with JUnit XML generation enabled, the Pants pytest_runner [uses `output_directories` instead of `output_files` to make the output file known to the process executor](https://github.com/pantsbuild/pants/blob/master/src/python/pants/backend/python/rules/pytest_runner.py#L237-L245). This works fine with local execution but breaks with remote execution because RE servers can skip `output_directories` that are not in fact directories.

This issue manifests as errors like this:

```
$ ./pants --pytest-junit-xml-dir=dist/test-results [remote-config options] test XXX
05:07:26.01 [INFO] Completed: Run Pytest for XXX
05:07:26.02 [WARN] Failed to generate JUnit XML data for XXX.
05:07:26.02 [INFO] Tests failed: XXX
𐄂 XXX
ERROR: --junitxml must be a filename, given: XXX.xml
```

Use `output_files` instead for the JUnit XML generation file.

The test runs and JUnit XML is properly generated and written to the local filesystem.

Co-authored-by: Tom Dyas <tdyas@toolchain.com>
@tdyas tdyas deleted the use_output_files_for_junit_xml branch February 20, 2023 20:41
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

4 participants