Skip to content

Commit 27276b6

Browse files
mortenmjrickeylev
andauthored
fix: Prefix bootstrap file to prevent pytest reentrance (bazel-contrib#2230)
Pytest will, by default, discover tests in files named `test_*.py`. The existing behaviour of the bootstrap setup is to create a file named e.g. `test_foo_stage2_bootstrap.py` for a target named `test_foo`. This causes pytest to reenter, leading to a crash. To fix, prepend the generated stage2 file with an underscore so that pytest doesn't match it. --------- Co-authored-by: Richard Levasseur <[email protected]>
1 parent 654b4d5 commit 27276b6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ A brief description of the categories of changes:
5757
([#2186](https://github.com/bazelbuild/rules_python/issues/2186)).
5858
* (py_wheel) Fix incorrectly generated `Required-Dist` when specifying requirements with markers
5959
in extra_requires in py_wheel rule.
60+
* (rules) Prevent pytest from trying run the generated stage2
61+
bootstrap .py file when using {obj}`--bootstrap_impl=script`
6062

6163

6264
### Added

python/private/common/py_executable_bazel.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ def _create_stage2_bootstrap(
330330
imports,
331331
runtime_details):
332332
output = ctx.actions.declare_file(
333-
"{}_stage2_bootstrap.py".format(output_prefix),
333+
# Prepend with underscore to prevent pytest from trying to
334+
# process the bootstrap for files starting with `test_`
335+
"_{}_stage2_bootstrap.py".format(output_prefix),
334336
sibling = output_sibling,
335337
)
336338
runtime = runtime_details.effective_runtime

0 commit comments

Comments
 (0)