Skip to content

tests: run pytest under Python devmode#5715

Merged
henryiii merged 5 commits into
pybind:masterfrom
XuehaiPan:pytest-devmode
Jun 6, 2025
Merged

tests: run pytest under Python devmode#5715
henryiii merged 5 commits into
pybind:masterfrom
XuehaiPan:pytest-devmode

Conversation

@XuehaiPan

@XuehaiPan XuehaiPan commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

required: true
type: string

env:

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Wait for Python 3.14.0b3 release for:

to resolve the segmentation faults in tests.

@Skylion007

Copy link
Copy Markdown
Collaborator

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

@XuehaiPan

XuehaiPan commented Jun 5, 2025

Copy link
Copy Markdown
Contributor Author

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

henryiii commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

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

henryiii commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

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

henryiii commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

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

henryiii commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

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

rwgk commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

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

Yes.

Comment thread .github/workflows/ci.yml Outdated
@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

henryiii commented Jun 6, 2025

Copy link
Copy Markdown
Collaborator

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
@XuehaiPan XuehaiPan deleted the pytest-devmode branch November 15, 2025 05:41
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