Skip to content

Commit 64075f9

Browse files
committed
Skip invalid-self tests under Python 2
Python2 doesn't allow you to invoke __init__ with an invalid `self`: it gives you a TypeError (before the code gets to pybind): unbound method __init__() must be called with TestFactory1 instance as first argument (got TestFactory2 instance instead)
1 parent 2ac434f commit 64075f9

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def pytest_namespace():
211211
'requires_eigen_and_scipy': skipif(not have_eigen or not scipy,
212212
reason="eigen and/or scipy are not installed"),
213213
'unsupported_on_pypy': skipif(pypy, reason="unsupported on PyPy"),
214+
'unsupported_on_py2': skipif(sys.version_info.major < 3, reason="unsupported on Python 2.x"),
214215
'gc_collect': gc_collect
215216
}
216217

tests/test_factory_constructors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,11 @@ def test_reallocations(capture, msg):
413413
""")
414414

415415

416+
@pytest.unsupported_on_py2
416417
@pytest.mark.parametrize('which, bad', [(1, 1), (1, 2), (6, 1), (6, 2), (6, 3), (6, 4)])
417418
def test_invalid_self(which, bad, capture):
419+
"""Tests invocation of the pybind-registered base class with an invalid `self` argument. You
420+
can only actually do this on Python 3: Python 2 raises an exception itself if you try."""
418421
class NotPybindDerived(object):
419422
pass
420423

0 commit comments

Comments
 (0)