Skip to content

Allow pytest tests to be named test_#768

Closed
gabrielrussoc wants to merge 2 commits intoaspect-build:mainfrom
gabrielrussoc:fix-723
Closed

Allow pytest tests to be named test_#768
gabrielrussoc wants to merge 2 commits intoaspect-build:mainfrom
gabrielrussoc:fix-723

Conversation

@gabrielrussoc
Copy link
Copy Markdown

Fixes #723


Changes are visible to end-users: no

Test plan

bazelisk test //examples/pytest:test_pytest_test

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 7, 2026

CLA assistant check
All committers have signed the CLA.

@aspect-workflows
Copy link
Copy Markdown

aspect-workflows Bot commented Jan 7, 2026

test-os:linux-bzl:8 (Test)

2 test targets passed

Targets
//examples/pytest:sharded/test [k8-fastbuild]                     3s
//examples/pytest:test_pytest_test [k8-fastbuild]                 2s

Total test execution time was 5s. 36 tests (94.7%) were fully cached saving 56s.


test-os:linux-bzl:latest (Test)

⚠️ Buildkite build #2647 failed.


test-os:linux-bzl:8 (Test)

e2e

All tests were cache hits

14 tests (100.0%) were fully cached saving 10s.


test-os:linux-bzl:latest (Test)

e2e

⚠️ Buildkite build #2647 failed.


test-os:linux-bzl:8 (Test)

examples/uv_pip_compile

All tests were cache hits

1 test (100.0%) was fully cached saving 335ms.


test-os:linux-bzl:latest (Test)

examples/uv_pip_compile

Buildkite build #2647 is running...

Comment thread py/defs.bzl Outdated
fail("When pytest_main is set, the main attribute should not be set.")
pytest_main_target = name + ".pytest_main"
# Add a prefix to the test main to ensure targets called "test_*" do not get discovered by pytest.
pytest_main_target = "zzz_" + name + ".pytest_main"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sneaky with the zzz_. The zzz_ will show in the list of targets on query which might throw folks off. Would a prefix of just _ suffice?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done!

arrdem added a commit that referenced this pull request Mar 19, 2026
- test_multi_src: multiple test sources with test_* target name,
  the exact #723 reproduction scenario
- test_collection_check: asserts pytest collects only expected tests
  and no spurious generated files sneak into collection
- test_direct_pytest_main: cross-repo py_pytest_main() with test_*
  name, validating the dunder-wrap fix works outside the main repo

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@arrdem arrdem closed this in 57e6c37 Mar 19, 2026
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.

[Bug]: py_test targets cannot start with test_ if using pytest_main = True

3 participants