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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ concurrency:
cancel-in-progress: true

env:
PYTHONDEVMODE: 1
PIP_BREAK_SYSTEM_PACKAGES: 1
PIP_ONLY_BINARY: numpy
FORCE_COLOR: 3
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/reusable-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ 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.

PYTHONDEVMODE: 1
PIP_BREAK_SYSTEM_PACKAGES: 1
PIP_ONLY_BINARY: numpy
FORCE_COLOR: 3
PYTEST_TIMEOUT: 300
# For cmake:
VERBOSE: 1
CMAKE_COLOR_DIAGNOSTICS: 1

jobs:
standard:
name: 🧪
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def gc_collect():
gc.collect()
gc.collect()
gc.collect()
gc.collect()
gc.collect()


def pytest_configure():
Expand Down
18 changes: 12 additions & 6 deletions tests/test_methods_and_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,9 @@ def test_property_rvalue_policy():

# https://foss.heptapod.net/pypy/pypy/-/issues/2447
@pytest.mark.xfail("env.PYPY")
@pytest.mark.xfail(
sys.version_info == (3, 14, 0, "beta", 1)
or sys.version_info == (3, 14, 0, "beta", 2),
reason="3.14.0b1/2 bug: https://github.com/python/cpython/issues/133912",
strict=True,
@pytest.mark.skipif(
sys.version_info in ((3, 14, 0, "beta", 1), (3, 14, 0, "beta", 2)),
reason="3.14.0b1/2 managed dict bug: https://github.com/python/cpython/issues/133912",
)
def test_dynamic_attributes():
instance = m.DynamicClass()
Expand Down Expand Up @@ -337,25 +335,31 @@ def test_dynamic_attributes():
cstats = ConstructorStats.get(m.DynamicClass)
assert cstats.alive() == 1
del instance
pytest.gc_collect()
assert cstats.alive() == 0

# Derived classes should work as well
class PythonDerivedDynamicClass(m.DynamicClass):
pass

for cls in m.CppDerivedDynamicClass, PythonDerivedDynamicClass:
for cls in (m.CppDerivedDynamicClass, PythonDerivedDynamicClass):
derived = cls()
derived.foobar = 100
assert derived.foobar == 100

assert cstats.alive() == 1
del derived
pytest.gc_collect()
assert cstats.alive() == 0


# https://foss.heptapod.net/pypy/pypy/-/issues/2447
@pytest.mark.xfail("env.PYPY")
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
@pytest.mark.skipif(
sys.version_info in ((3, 14, 0, "beta", 1), (3, 14, 0, "beta", 2)),
reason="3.14.0b1/2 managed dict bug: https://github.com/python/cpython/issues/133912",
)
def test_cyclic_gc():
# One object references itself
instance = m.DynamicClass()
Expand All @@ -364,6 +368,7 @@ def test_cyclic_gc():
cstats = ConstructorStats.get(m.DynamicClass)
assert cstats.alive() == 1
del instance
pytest.gc_collect()
assert cstats.alive() == 0

# Two object reference each other
Expand All @@ -374,6 +379,7 @@ def test_cyclic_gc():

assert cstats.alive() == 2
del i1, i2
pytest.gc_collect()
assert cstats.alive() == 0


Expand Down
8 changes: 3 additions & 5 deletions tests/test_pickling.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ def test_roundtrip(cls_name):
[
pytest.param(
"PickleableWithDict",
marks=pytest.mark.xfail(
sys.version_info == (3, 14, 0, "beta", 1)
or sys.version_info == (3, 14, 0, "beta", 2),
reason="3.14.0b1/2 bug: https://github.com/python/cpython/issues/133912",
strict=True,
marks=pytest.mark.skipif(
sys.version_info in ((3, 14, 0, "beta", 1), (3, 14, 0, "beta", 2)),
reason="3.14.0b1/2 managed dict bug: https://github.com/python/cpython/issues/133912",
),
),
"PickleableWithDictNew",
Expand Down
Loading