Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
1a0ff405
Unverified
Commit
1a0ff405
authored
May 30, 2024
by
Henry Schreiner
Committed by
GitHub
May 30, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: avoid immortal objects in tests (#5150)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
parent
7187894e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
8 deletions
+8
-8
.github/workflows/ci.yml
+1
-1
tests/test_kwargs_and_defaults.py
+3
-4
tests/test_pytypes.py
+4
-3
No files found.
.github/workflows/ci.yml
View file @
1a0ff405
...
@@ -207,7 +207,7 @@ jobs:
...
@@ -207,7 +207,7 @@ jobs:
fetch-depth
:
0
fetch-depth
:
0
-
name
:
Prepare venv
-
name
:
Prepare venv
run
:
python3.13 -m venv .venv
run
:
python3.13
t
-m venv .venv
-
name
:
Install Python deps
-
name
:
Install Python deps
run
:
.venv/bin/pip install -r tests/requirements.txt
run
:
.venv/bin/pip install -r tests/requirements.txt
...
...
tests/test_kwargs_and_defaults.py
View file @
1a0ff405
import
pytest
import
pytest
from
pybind11_tests
import
PYBIND11_REFCNT_IMMORTAL
from
pybind11_tests
import
kwargs_and_defaults
as
m
from
pybind11_tests
import
kwargs_and_defaults
as
m
...
@@ -382,10 +381,10 @@ def test_args_refcount():
...
@@ -382,10 +381,10 @@ def test_args_refcount():
arguments"""
arguments"""
refcount
=
m
.
arg_refcount_h
refcount
=
m
.
arg_refcount_h
myval
=
54321
myval
=
object
()
expected
=
refcount
(
myval
)
expected
=
refcount
(
myval
)
assert
m
.
arg_refcount_h
(
myval
)
==
expected
assert
m
.
arg_refcount_h
(
myval
)
==
expected
assert
m
.
arg_refcount_o
(
myval
)
in
{
expected
+
1
,
PYBIND11_REFCNT_IMMORTAL
}
assert
m
.
arg_refcount_o
(
myval
)
==
expected
+
1
assert
m
.
arg_refcount_h
(
myval
)
==
expected
assert
m
.
arg_refcount_h
(
myval
)
==
expected
assert
refcount
(
myval
)
==
expected
assert
refcount
(
myval
)
==
expected
...
@@ -421,7 +420,7 @@ def test_args_refcount():
...
@@ -421,7 +420,7 @@ def test_args_refcount():
# for the `py::args`; in the previous case, we could simply inc_ref and pass on Python's input
# for the `py::args`; in the previous case, we could simply inc_ref and pass on Python's input
# tuple without having to inc_ref the individual elements, but here we can't, hence the extra
# tuple without having to inc_ref the individual elements, but here we can't, hence the extra
# refs.
# refs.
exp3_3
=
PYBIND11_REFCNT_IMMORTAL
if
exp3
==
PYBIND11_REFCNT_IMMORTAL
else
exp3
+
3
exp3_3
=
exp3
+
3
assert
m
.
mixed_args_refcount
(
myval
,
myval
,
myval
)
==
(
exp3_3
,
exp3_3
,
exp3_3
)
assert
m
.
mixed_args_refcount
(
myval
,
myval
,
myval
)
==
(
exp3_3
,
exp3_3
,
exp3_3
)
assert
m
.
class_default_argument
()
==
"<class 'decimal.Decimal'>"
assert
m
.
class_default_argument
()
==
"<class 'decimal.Decimal'>"
tests/test_pytypes.py
View file @
1a0ff405
...
@@ -5,7 +5,7 @@ import types
...
@@ -5,7 +5,7 @@ import types
import
pytest
import
pytest
import
env
import
env
from
pybind11_tests
import
PYBIND11_REFCNT_IMMORTAL
,
detailed_error_messages_enabled
from
pybind11_tests
import
detailed_error_messages_enabled
from
pybind11_tests
import
pytypes
as
m
from
pybind11_tests
import
pytypes
as
m
...
@@ -631,11 +631,12 @@ def test_memoryview(method, args, fmt, expected_view):
...
@@ -631,11 +631,12 @@ def test_memoryview(method, args, fmt, expected_view):
],
],
)
)
def
test_memoryview_refcount
(
method
):
def
test_memoryview_refcount
(
method
):
buf
=
b
"
\x0a\x0b\x0c\x0d
"
# Avoiding a literal to avoid an immortal object in free-threaded builds
buf
=
"
\x0a\x0b\x0c\x0d
"
.
encode
(
"ascii"
)
ref_before
=
sys
.
getrefcount
(
buf
)
ref_before
=
sys
.
getrefcount
(
buf
)
view
=
method
(
buf
)
view
=
method
(
buf
)
ref_after
=
sys
.
getrefcount
(
buf
)
ref_after
=
sys
.
getrefcount
(
buf
)
assert
ref_before
<
ref_after
or
ref_before
==
ref_after
==
PYBIND11_REFCNT_IMMORTAL
assert
ref_before
<
ref_after
assert
list
(
view
)
==
list
(
buf
)
assert
list
(
view
)
==
list
(
buf
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment