tests: cleanup and ci hardening (#2397)
* tests: refactor and cleanup
* refactor: more consistent
* tests: vendor six
* tests: more xfails, nicer system
* tests: simplify to info
* tests: suggestions from @YannickJadoul and @bstaletic
* tests: restore some pypy tests that now pass
* tests: rename info to env
* tests: strict False/True
* tests: drop explicit strict=True again
* tests: reduce minimum PyTest to 3.1
diff --git a/tests/test_builtin_casters.py b/tests/test_builtin_casters.py
index c905766..08d38bc 100644
--- a/tests/test_builtin_casters.py
+++ b/tests/test_builtin_casters.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import pytest
+import env # noqa: F401
+
from pybind11_tests import builtin_casters as m
from pybind11_tests import UserType, IncType
@@ -117,10 +119,7 @@
# Issue #816
def to_bytes(s):
- if pytest.PY2:
- b = s
- else:
- b = s.encode("utf8")
+ b = s if env.PY2 else s.encode("utf8")
assert isinstance(b, bytes)
return b
@@ -197,7 +196,7 @@
assert m.i64_str(-1) == "-1"
assert m.i32_str(2000000000) == "2000000000"
assert m.u32_str(2000000000) == "2000000000"
- if pytest.PY2:
+ if env.PY2:
assert m.i32_str(long(-1)) == "-1" # noqa: F821 undefined name 'long'
assert m.i64_str(long(-1)) == "-1" # noqa: F821 undefined name 'long'
assert m.i64_str(long(-999999999999)) == "-999999999999" # noqa: F821 undefined name
@@ -219,7 +218,7 @@
m.i32_str(3000000000)
assert "incompatible function arguments" in str(excinfo.value)
- if pytest.PY2:
+ if env.PY2:
with pytest.raises(TypeError) as excinfo:
m.u32_str(long(-1)) # noqa: F821 undefined name 'long'
assert "incompatible function arguments" in str(excinfo.value)
@@ -360,9 +359,9 @@
assert convert(A(False)) is False
-@pytest.requires_numpy
def test_numpy_bool():
- import numpy as np
+ np = pytest.importorskip("numpy")
+
convert, noconvert = m.bool_passthrough, m.bool_passthrough_noconvert
def cant_convert(v):