Conversation
ea44b1b to
bfeef2e
Compare
|
It works! |
693db65 to
2e09de0
Compare
|
Since opening this PR, I’ve realized there’s a key issue that needs to be accounted for:
One potential solution would be to update [test-collector-python] to use a [filelock][filelock] and append or merge results into the JSON file in a thread/process-safe way. This would allow multiple processes to contribute to a single result file without clobbering each other, and still keep things compatible with test-engine-client. |
|
Hi @jasonwbarnett. Thank you for opening the PR. I might be missing some contexts here, but can you explain more about the support you want to add, or the use case you might have?
We do have other features, such as muting or retrying tests. If that's something you'd want to achieve, we could add the support, but but it might require a slightly different approach compared to other test runners with splitting support. |
|
@nprizal Exactly! We’re primarily interested in the muting and retry features. Test splitting isn’t feasible in our case due to Pants, which already has richer context about the test structure. It’s not that it couldn’t be done, it’s just not a priority for us right now. What we’re really eager for is the ability to automatically mute flaky tests and allow developers to manually mark tests as flaky so their results can be excluded. |
|
@jasonwbarnett Got it! After looking at your changes, it seems like the runner behaves slightly differently when using // pytest.go
type Pytest struct {}
func NewPytest(c Config) Pytest {
...
}
func (p Pytest) GetFiles() (string[], error) {
...
}
func (p Pytest) Run(...) error {
...
err = runAndForwardSignal(cmd)
...
err = HandlePytestResult(result, p.ResultPath)
...
}
func HandlePytestResult(result RunResult, path string) error { // this is the shared function
tests, err := ParsePytestCollectorResult(p.ResultPath)
...
for _, test := range tests {
result.RecordTestResult(...)
}
...
} // pytest_pants.go
type PytestPants struct {}
func NewPytestPants(c Config) {
...
}
func (p PytestPants) GetFiles() (string[], error) {
return []string{}, nil
}
func (p PytestPants) Run(...) error {
...
err = runAndForwardSignal(cmd)
...
err = HandlePytestResult(result, p.ResultPath)
...
}We are also planning of extracting the results handling, including the parsing, separately from the runner in the future. So that the
This sounds like a sensible approach. My main concern is that in the current |
48a75d7 to
df291c5
Compare
|
@nprizal I’ve updated the PR and implemented a distinct This setup works, but note that the results are currently overwritten with each test run orchestrated by pants, so only one test result is retained. This will be resolved once buildkite/test-collector-python#55 is merged and published to PyPI. I'm pretty sure CI should pass with the addition of pants into the docker image, but I'm not fully sure. Let me know if it needs any changes to pass. |
0e203d1 to
e4eab4e
Compare
0cdde1b to
54b2420
Compare
|
Tests are passing locally: |
98e5300 to
35dc597
Compare
539a2b6 to
0ff4bd8
Compare
|
I just finished adding documentation to this PR. I'm a little confused what to label and name things because pants can technically run many different types of tests, i.e. python, javascript, kotlin, golang, scala, typescript, etc This PR is strictly aiming to support Python which is arguably the most predominantly used language in pants. I'm open to changing the naming of things as you see fit. Cheers! |
0ff4bd8 to
7365401
Compare
|
I confirmed the --merge-json flag works as expected. with --merge-jsonWithout --merge-json |
|
I'm blocked until buildkite/test-collector-python#55 is merged and published on pypi.org. The tests and code depend on it now that I'm planning to require --merge-json argument. |
nprizal
left a comment
There was a problem hiding this comment.
Overall looks good. I have comments around the naming and the test plan creation. I have also turned on the 3rd party contributor build, so next time you push a commit, it should trigger a CI build in the pipeline.
main.go
Outdated
| debug.Println("Creating test plan") | ||
| testPlan, err := apiClient.CreateTestPlan(ctx, cfg.SuiteSlug, params) | ||
| var testPlan plan.TestPlan | ||
| if params.Runner != "pytestpants" { |
There was a problem hiding this comment.
We still need to create the test plan to get the list of muted tests from the server.
There was a problem hiding this comment.
Ah, good catch — I meant to pull that out before opening the PR. I started looking into where the list of supported runners is coming from, and it seemed like it was hardcoded in the server-side API, since the request fails when using pytestpants and returns a list of valid runners. But now I’m second-guessing myself — it might actually be this client that’s doing the filtering, and I just failed to track it down properly.
When main.go is reverted to the main branch I get this:
Buildkite Test Engine Client: Couldn't fetch or create test plan: Invalid parameters: Runner must be one of "rspec", "jest", "cypress", "playwright", "gotest", "pytest", "cucumber"
It does appear to be that the server side API is validating the client and since this is new, it's throwing it out. Maybe I need to figure out how to send pytest to the call, even though it's coming from the pytest-pants runner?
Mind taking a quick look or pointing me in the right direction?
There was a problem hiding this comment.
I found where it's building params for the request and just swapped it with pytest (source here). Let me know if I should do something else here.
ff33821 to
d8d858c
Compare
cdfa8c3 to
db467c9
Compare
|
@nprizal Can you unblock the build pipeline? |
|
@nprizal Thanks for the support. It looks like the tests are passing! 🎉 🎉 |
|
@nprizal I tested everything end to end in our monorepo. Things look good. |
nprizal
left a comment
There was a problem hiding this comment.
This looks great 🚀! The changes are isolated, and won't affect the existing pytest runner and other common behavior. I have few non blocking comments.
| }, nil | ||
| } | ||
|
|
||
| if cfg.TestRunner == "pytest-pants" { |
There was a problem hiding this comment.
We can maybe add a comment to explain why this is necessary?
Thanks! I'll get to this in an hour. |
c042e79 to
bf5ade5
Compare
|
@nprizal I've updated the code with the two requested changes. Should I squash all commits or will you do that on merge? |
nprizal
left a comment
There was a problem hiding this comment.
@jasonwbarnett Thanks for adding the comment! Could you please squash the commits? Once you’ve done that, I’ll merge the PR and create a release candidate so your team can begin testing it.
bf5ade5 to
b785e85
Compare
|
@nprizal squashed and pushed. |
|
@jasonwbarnett I have created a release candidate that includes this PR |
|
I just realized I failed to update the PR description before this was merged. It's wildly inaccurate. Is there anyway to fix it? |
|
@jasonwbarnett I think you can still edit the PR description. |
|
@nprizal Great. The PR description is updated. |
Description
Adds experimental support for running
pytesttests using pants via a newpytest-pantstest runner in bktec. This enables teams using Pants to integrate with Buildkite Test Analytics while retaining core retry and mute capabilities.Context
#315
Changes
pytest-pantsas a new supported runner typepytest_pants.go) with validation and command constructionpytest-pantstest plans to the API aspytestfor compatibilityTesting
pytest-pantsinpytest_pants_test.gotestdata/pytest_pants