-
Notifications
You must be signed in to change notification settings - Fork 14
pytest-pants: add JUnit XML output support, make test collector optional #534
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,6 +153,148 @@ func TestPytestPantsGetExamples(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestPytestPantsRun_JUnit_TestPassed(t *testing.T) { | ||
| changeCwd(t, "./testdata/pytest_pants") | ||
|
|
||
| pytest := PytestPants{ | ||
| RunnerConfig: RunnerConfig{ | ||
| TestCommand: "pants test //passing_test.py -- --junit-xml={{resultPath}}", | ||
| ResultPath: "result-passed.xml", | ||
| }, | ||
| resultFormat: "junit", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: These JUnit tests set |
||
| } | ||
|
|
||
| testCases := []plan.TestCase{{Path: "passing_test.py"}} | ||
| result := NewRunResult([]plan.TestCase{}) | ||
| err := pytest.Run(result, testCases, false) | ||
| if err != nil { | ||
| t.Errorf("PytestPants.Run(%q) error = %v", testCases, err) | ||
| } | ||
|
|
||
| if result.Status() != RunStatusPassed { | ||
| t.Errorf("PytestPants.Run(%q) RunResult.Status = %v, want %v", testCases, result.Status(), RunStatusPassed) | ||
| } | ||
| } | ||
|
|
||
| func TestPytestPantsRun_JUnit_TestFailed(t *testing.T) { | ||
| changeCwd(t, "./testdata/pytest_pants") | ||
|
|
||
| pytest := PytestPants{ | ||
| RunnerConfig: RunnerConfig{ | ||
| TestCommand: "pants test //:: -- --junit-xml={{resultPath}}", | ||
| ResultPath: "result-failed.xml", | ||
| }, | ||
| resultFormat: "junit", | ||
| } | ||
|
|
||
| testCases := []plan.TestCase{{Path: "failing_test.py"}} | ||
| result := NewRunResult([]plan.TestCase{}) | ||
| err := pytest.Run(result, testCases, false) | ||
|
|
||
| exitError := new(exec.ExitError) | ||
| assert.ErrorAs(t, err, &exitError) | ||
|
|
||
| if result.Status() != RunStatusFailed { | ||
| t.Errorf("PytestPants.Run(%q) RunResult.Status = %v, want %v", testCases, result.Status(), RunStatusFailed) | ||
| } | ||
|
|
||
| failedTest := result.FailedTests() | ||
| if len(failedTest) != 1 { | ||
| t.Errorf("len(result.FailedTests()) = %d, want 1", len(failedTest)) | ||
| } | ||
|
|
||
| wantFailedTests := []plan.TestCase{ | ||
| { | ||
| Format: "example", | ||
| Identifier: "tests/failing_test.py::test_failed", | ||
| Name: "test_failed", | ||
| Path: "tests/failing_test.py::test_failed", | ||
| Scope: "tests/failing_test.py", | ||
| }, | ||
| } | ||
|
|
||
| if diff := cmp.Diff(failedTest, wantFailedTests); diff != "" { | ||
| t.Errorf("PytestPants.Run(%q) RunResult.FailedTests() diff (-got +want):\n%s", testCases, diff) | ||
| } | ||
| } | ||
|
|
||
| func TestPytestPantsResultFormat_JUnit(t *testing.T) { | ||
| pytest := PytestPants{resultFormat: "junit"} | ||
| if got := pytest.ResultFormat(); got != "junit" { | ||
| t.Errorf("ResultFormat() = %q, want %q", got, "junit") | ||
| } | ||
| } | ||
|
|
||
| func TestPytestPantsResultFormat_JSON(t *testing.T) { | ||
| pytest := PytestPants{resultFormat: "json"} | ||
| if got := pytest.ResultFormat(); got != "" { | ||
| t.Errorf("ResultFormat() = %q, want %q", got, "") | ||
| } | ||
| } | ||
|
|
||
| func TestPytestPantsCommandNameAndArgs_JUnit_ValidCommand(t *testing.T) { | ||
| testCases := []plan.TestCase{{Path: "failing_test.py"}, {Path: "passing_test.py"}} | ||
| testCommand := "pants test //:: -- --junit-xml={{resultPath}}" | ||
|
|
||
| pytest := PytestPants{ | ||
| RunnerConfig: RunnerConfig{ | ||
| TestCommand: testCommand, | ||
| ResultPath: "result.xml", | ||
| }, | ||
| resultFormat: "junit", | ||
| } | ||
|
|
||
| gotName, gotArgs, err := pytest.CommandNameAndArgs(testCases, false) | ||
| if err != nil { | ||
| t.Errorf("commandNameAndArgs(%q, %q) error = %v", testCases, testCommand, err) | ||
| } | ||
|
|
||
| wantName := "pants" | ||
| wantArgs := []string{"test", "//::", "--", "--junit-xml=result.xml"} | ||
|
|
||
| if diff := cmp.Diff(gotName, wantName); diff != "" { | ||
| t.Errorf("commandNameAndArgs() diff (-got +want):\n%s", diff) | ||
| } | ||
| if diff := cmp.Diff(gotArgs, wantArgs); diff != "" { | ||
| t.Errorf("commandNameAndArgs() diff (-got +want):\n%s", diff) | ||
| } | ||
| } | ||
|
|
||
| func TestPytestPantsCommandNameAndArgs_JUnit_WithoutResultPath(t *testing.T) { | ||
| testCases := []plan.TestCase{{Path: "failing_test.py"}} | ||
| testCommand := "pants test //:: -- --merge-json" | ||
|
|
||
| pytest := PytestPants{ | ||
| RunnerConfig: RunnerConfig{ | ||
| TestCommand: testCommand, | ||
| ResultPath: "result.xml", | ||
| }, | ||
| resultFormat: "junit", | ||
| } | ||
|
|
||
| _, _, err := pytest.CommandNameAndArgs(testCases, false) | ||
| if err == nil { | ||
| t.Error("commandNameAndArgs() error = nil, want error") | ||
| } | ||
| } | ||
|
|
||
| func TestPytestPantsCommandNameAndArgs_NeitherResultFlag(t *testing.T) { | ||
| testCases := []plan.TestCase{{Path: "failing_test.py"}} | ||
|
|
||
| pytest := PytestPants{ | ||
| RunnerConfig: RunnerConfig{ | ||
| TestCommand: "pants test //:: -- --some-other-flag", | ||
| ResultPath: "result.json", | ||
| }, | ||
| resultFormat: "", | ||
| } | ||
|
|
||
| _, _, err := pytest.CommandNameAndArgs(testCases, false) | ||
| if err == nil { | ||
| t.Error("commandNameAndArgs() error = nil, want error") | ||
| } | ||
| } | ||
|
|
||
| func TestPytestPantsCommandNameAndArgs_WithoutMergeJson(t *testing.T) { | ||
| testCases := []plan.TestCase{{Path: "failing_test.py"}, {Path: "passing_test.py"}} | ||
| testCommand := "pants test //:: -- --json={{resultPath}}" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: This
"json"value flows throughResultFormat()intouploadResults, so whenBUILDKITE_TEST_ENGINE_UPLOAD_RESULTSis set, bktec will now upload the result file for the JSON path. The siblingpytestrunner returns""for its collector/JSON case (seepytest.go'sResultFormat()), deliberately leaving the upload tobuildkite-test-collector, which sends results directly viaBUILDKITE_ANALYTICS_TOKEN(set inbuildCommand). Is the divergence here intentional — e.g. the collector doesn't receive the token inside the pants sandbox, so bktec has to do the upload — or could this end up uploading the same results twice?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in the latest commit.