1 """pytest configuration 3 Extends output capture as needed by pybind11: ignore constructors, optional unordered lines. 4 Adds docstring and exceptions message sanitizers: ignore Python 2 vs 3 differences. 16 _unicode_marker = re.compile(
r'u(\'[^\']*\')')
17 _long_marker = re.compile(
r'([0-9])L')
18 _hexadecimal = re.compile(
r'0x[0-9a-fA-F]+')
22 if sys.version_info[:2] < (3, 5):
23 collect_ignore.append(
"test_async.py")
27 """For triple-quote strings""" 28 return textwrap.dedent(s.lstrip(
'\n').rstrip())
32 """For output which does not require specific line order""" 37 """Explanation for a failed assert -- the a and b arguments are List[str]""" 38 return [
"--- actual / +++ expected"] + [line.strip(
'\n')
for line
in difflib.ndiff(a, b)]
42 """Basic output post-processing and comparison""" 52 a = [line
for line
in self.
string.strip().splitlines()
if not line.startswith(
"###")]
62 """Custom comparison for output without strict line ordering""" 80 self.
capfd.readouterr()
99 return item
in self.
out 112 """Extended `capsys` with context manager and custom equality operators""" 138 s = s.replace(
"pybind11_tests.",
"m.")
139 s = s.replace(
"unicode",
"str")
140 s = _long_marker.sub(
r"\1", s)
141 s = _unicode_marker.sub(
r"\1", s)
153 """Sanitize docstrings and add custom failure explanation""" 160 s = _hexadecimal.sub(
"0", s)
166 """Sanitize messages and add custom failure explanation""" 172 """Hook to insert custom failure explanation""" 173 if hasattr(left,
'explanation'):
174 return left.explanation
177 @contextlib.contextmanager
179 """Suppress the desired exception""" 187 ''' Run the garbage collector twice (needed when running 188 reference counting tests with PyPy) ''' 194 """Add import suppression and test requirements to `pytest` namespace""" 204 from pybind11_tests.eigen
import have_eigen
207 pypy = platform.python_implementation() ==
"PyPy" 209 skipif = pytest.mark.skipif
210 pytest.suppress = suppress
211 pytest.requires_numpy = skipif(
not np, reason=
"numpy is not installed")
212 pytest.requires_scipy = skipif(
not np, reason=
"scipy is not installed")
213 pytest.requires_eigen_and_numpy = skipif(
not have_eigen
or not np,
214 reason=
"eigen and/or numpy are not installed")
215 pytest.requires_eigen_and_scipy = skipif(
216 not have_eigen
or not scipy, reason=
"eigen and/or scipy are not installed")
217 pytest.unsupported_on_pypy = skipif(pypy, reason=
"unsupported on PyPy")
218 pytest.unsupported_on_py2 = skipif(sys.version_info.major < 3,
219 reason=
"unsupported on Python 2.x")
220 pytest.gc_collect = gc_collect
224 """Early diagnostic for test module initialization errors 226 When there is an error during initialization, the first import will report the 227 real error while all subsequent imports will report nonsense. This import test 228 is done early (in the pytest configuration file, before any tests) in order to 229 avoid the noise of having all tests fail with identical error messages. 231 Any possible exception is caught here and reported manually *without* the stack 232 trace. This further reduces noise since the trace would only show pytest internals 233 which are not useful for debugging pybind11 module issues. 237 import pybind11_tests
238 except Exception
as e:
239 print(
"Failed to import pybind11_tests from pytest:")
def __init__(self, sanitizer)
def __contains__(self, item)
auto format(const std::locale &loc, const CharT *fmt, const Streamable &tp) -> decltype(to_stream(std::declval< std::basic_ostream< CharT > &>(), fmt, tp), std::basic_string< CharT >
def pytest_assertrepr_compare(op, left, right)
def _make_explanation(a, b)
def _sanitize_docstring(thing)
def _sanitize_message(thing)
const detail::type_info * type
def __init__(self, string)
def _test_import_pybind11()
def __call__(self, thing)
void print(Args &&...args)
def __init__(self, capfd)
bool hasattr(handle obj, handle name)