Skip to content

Commit d8d858c

Browse files
committed
revert back to calling server for test plan
1 parent 8eb05fd commit d8d858c

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ To configure the test runner for bktec, please refer to the detailed guides prov
6060
- [Playwright](./docs/playwright.md)
6161
- [Cypress](./docs/cypress.md)
6262
- [pytest](./docs/pytest.md)
63-
- [pytest pants](./docs/pytestpants.md)
63+
- [pytest pants](./docs/pytest-pants.md)
6464
- [go test](./docs/gotest.md)
6565
- [RSpec](./docs/rspec.md)
6666

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
> - Split slow files by individual test example
1313
> - Skip tests
1414
15-
To integrate bktec with pants, you need to [install and configure Buildkite Test Collector for pytest](https://buildkite.com/docs/test-engine/python-collectors#pytest-collector) first. Then set the `BUILDKITE_TEST_ENGINE_TEST_RUNNER` environment variable to `pytestpants`.
15+
To integrate bktec with pants, you need to [install and configure Buildkite Test Collector for pytest](https://buildkite.com/docs/test-engine/python-collectors#pytest-collector) first. Then set the `BUILDKITE_TEST_ENGINE_TEST_RUNNER` environment variable to `pytest-pants`.
1616

1717
Look at the example configuration files in the [pytest_pants testdata directory](../internal/runner/testdata/pytest_pants) for an example of how to add buildkite-test-collector to the pants resolve used by pytest. Specifically:
1818

@@ -29,7 +29,7 @@ pants generate-lockfiles --resolve=pytest
2929
Only running `pants test` with `python_test` targets is supported at this time.
3030

3131
```sh
32-
export BUILDKITE_TEST_ENGINE_TEST_RUNNER=pytestpants
32+
export BUILDKITE_TEST_ENGINE_TEST_RUNNER=pytest-pants
3333
export BUILDKITE_TEST_ENGINE_TEST_CMD="pants --filter-target-type=python_test --changed-since=HEAD~1 test -- --json={{resultPath}} --merge-json"
3434
bktec
3535
```

internal/config/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (c *Config) validate() error {
6060
c.errs.appendFieldError("BUILDKITE_TEST_ENGINE_SUITE_SLUG", "must not be blank")
6161
}
6262

63-
if c.ResultPath == "" && c.TestRunner != "cypress" && c.TestRunner != "pytest" && c.TestRunner != "pytestpants" {
63+
if c.ResultPath == "" && c.TestRunner != "cypress" && c.TestRunner != "pytest" && c.TestRunner != "pytest-pants" {
6464
c.errs.appendFieldError("BUILDKITE_TEST_ENGINE_RESULT_PATH", "must not be blank")
6565
}
6666

internal/runner/detector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ func DetectRunner(cfg config.Config) (TestRunner, error) {
4747
return NewPlaywright(runnerConfig), nil
4848
case "pytest":
4949
return NewPytest(runnerConfig), nil
50-
case "pytestpants":
50+
case "pytest-pants":
5151
return NewPytestPants(runnerConfig), nil
5252
case "gotest":
5353
return NewGoTest(runnerConfig), nil
5454
default:
5555
// Update the error message to include the new runner
56-
return nil, errors.New("runner value is invalid, possible values are 'rspec', 'jest', 'cypress', 'playwright', 'pytest', 'pytestpants', or 'gotest'")
56+
return nil, errors.New("runner value is invalid, possible values are 'rspec', 'jest', 'cypress', 'playwright', 'pytest', 'pytest-pants', or 'gotest'")
5757
}
5858
}

internal/runner/pytest_pants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type PytestPants struct {
1616
}
1717

1818
func (p PytestPants) Name() string {
19-
return "pytest"
19+
return "pytest-pants"
2020
}
2121

2222
func NewPytestPants(c RunnerConfig) PytestPants {

main.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -361,25 +361,19 @@ func fetchOrCreateTestPlan(ctx context.Context, apiClient *api.Client, cfg confi
361361
return handleError(err)
362362
}
363363

364-
var testPlan plan.TestPlan
365-
if params.Runner != "pytestpants" {
366-
debug.Println("Creating test plan")
367-
createdPlan, err := apiClient.CreateTestPlan(ctx, cfg.SuiteSlug, params)
364+
debug.Println("Creating test plan")
365+
testPlan, err := apiClient.CreateTestPlan(ctx, cfg.SuiteSlug, params)
368366

369-
if err != nil {
370-
return handleError(err)
371-
}
367+
if err != nil {
368+
return handleError(err)
369+
}
372370

373-
// The server can return an "error" plan indicated by an empty task list (i.e. `{"tasks": {}}`).
374-
// In this case, we should create a fallback plan.
375-
if len(createdPlan.Tasks) == 0 {
376-
fmt.Println("⚠️ Error plan received, falling back to non-intelligent splitting. Your build may take longer than usual.")
377-
testPlan = plan.CreateFallbackPlan(files, cfg.Parallelism)
378-
} else {
379-
testPlan = createdPlan
380-
}
381-
} else {
371+
// The server can return an "error" plan indicated by an empty task list (i.e. `{"tasks": {}}`).
372+
// In this case, we should create a fallback plan.
373+
if len(testPlan.Tasks) == 0 {
374+
fmt.Println("⚠️ Error plan received, falling back to non-intelligent splitting. Your build may take longer than usual.")
382375
testPlan = plan.CreateFallbackPlan(files, cfg.Parallelism)
376+
return testPlan, nil
383377
}
384378

385379
debug.Printf("Test plan created. Identifier: %q", cfg.Identifier)
@@ -399,15 +393,21 @@ func createRequestParam(ctx context.Context, cfg config.Config, files []string,
399393

400394
// Splitting files by example is only supported for rspec runner.
401395
if runner.Name() != "RSpec" {
402-
return api.TestPlanParams{
396+
params := api.TestPlanParams{
403397
Identifier: cfg.Identifier,
404398
Parallelism: cfg.Parallelism,
405399
Branch: cfg.Branch,
406400
Runner: cfg.TestRunner,
407401
Tests: api.TestPlanParamsTest{
408402
Files: testFiles,
409403
},
410-
}, nil
404+
}
405+
406+
if cfg.TestRunner == "pytest-pants" {
407+
params.Runner = "pytest"
408+
}
409+
410+
return params, nil
411411
}
412412

413413
if cfg.SplitByExample {

0 commit comments

Comments
 (0)