Skip to content

tests: run pytest under Python devmode #5715

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

Merged
merged 5 commits into from
Jun 6, 2025

Conversation

XuehaiPan
Copy link
Contributor

@XuehaiPan XuehaiPan commented Jun 4, 2025

Description

See also: https://docs.python.org/3/library/devmode.html

The Python devmode can be enabled via:

python3 -X dev ...

or

PYTHONDEVMODE=1 python3 ...

Suggested changelog entry:

  • run pytest under Python devmode

@XuehaiPan XuehaiPan marked this pull request as ready for review June 4, 2025 06:02
@XuehaiPan XuehaiPan requested a review from henryiii as a code owner June 4, 2025 06:02
@XuehaiPan
Copy link
Contributor Author

Alright, the flaky test previously found in #5706 is caused by enabling more Python tracing.

@@ -14,6 +14,17 @@ on:
required: true
type: string

env:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NB: reusable workflows will not inherit env from the caller workflow.

@XuehaiPan
Copy link
Contributor Author

Wait for Python 3.14.0b3 release for:

to resolve the segmentation faults in tests.

@Skylion007
Copy link
Collaborator

Interesting, why does it segfault under devmode? Is this indicative of a serious error I wonder?

@XuehaiPan
Copy link
Contributor Author

XuehaiPan commented Jun 5, 2025

why does it segfault under devmode?

From the devmode docs: https://docs.python.org/3/library/devmode.html

Install debug hooks on memory allocators to check for:

  • Buffer underflow
  • Buffer overflow
  • Memory allocator API violation
  • Unsafe usage of the GIL

See the PyMem_SetupDebugHooks() C function.

It behaves as if the PYTHONMALLOC environment variable is set to debug.

To enable the Python Development Mode without installing debug hooks on memory allocators, set the PYTHONMALLOC environment variable to default.

@henryiii
Copy link
Collaborator

henryiii commented Jun 5, 2025

I can verify that it still segfaults on the latest 3.14t (https://github.com/python/cpython/tree/5b39741a0952624ed31dfe312ad32b067353ea7b), so 3.14b3 won't fix it.

@henryiii
Copy link
Collaborator

henryiii commented Jun 5, 2025

Ohh, interesting, if I swap xfail for skipif, then it passes. So it's messing up the state and the fix doesn't seem to be working. Shouldn't it be xpassing with current 3.14 branch build?

@henryiii
Copy link
Collaborator

henryiii commented Jun 5, 2025

Ahh, no, I take it back, I did a proper rebuild and the latest 3.14t does work without segfault in dev mode. So yes, this is just a leftover from this bug.

@henryiii
Copy link
Collaborator

henryiii commented Jun 5, 2025

I think we need to drop the gc tests on free-threaded Python. Unless there's some way to guarantee a stop-the-world event occurs, but I believe the general option is "never rely on the gc to remove anything at some time".

@rwgk
Copy link
Collaborator

rwgk commented Jun 5, 2025

I think we need to drop the gc tests on free-threaded Python.

Yes.

@henryiii henryiii merged commit 6c5d25a into pybind:master Jun 6, 2025
82 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jun 6, 2025
@henryiii
Copy link
Collaborator

henryiii commented Jun 6, 2025

Thanks!

@henryiii henryiii changed the title test: run pytest under Python devmode tests: run pytest under Python devmode Jun 19, 2025
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Jul 10, 2025
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.

4 participants