1 """pytest configuration 3 Extends output capture as needed by pybind11: ignore constructors, optional unordered lines. 4 Adds docstring and exceptions message sanitizers. 18 _long_marker = re.compile(
r"([0-9])L")
19 _hexadecimal = re.compile(
r"0x[0-9a-fA-F]+")
26 """For triple-quote strings""" 27 return textwrap.dedent(s.lstrip(
"\n").rstrip())
31 """For output which does not require specific line order""" 36 """Explanation for a failed assert -- the a and b arguments are List[str]""" 37 return [
"--- actual / +++ expected"] + [
38 line.strip(
"\n")
for line
in difflib.ndiff(a, b)
43 """Basic output post-processing and comparison""" 56 for line
in self.
string.strip().splitlines()
57 if not line.startswith(
"###")
68 """Custom comparison for output without strict line ordering""" 87 self.
capfd.readouterr()
106 return item
in self.
out 119 """Extended `capsys` with context manager and custom equality operators""" 145 s = s.replace(
"pybind11_tests.",
"m.")
146 s = _long_marker.sub(
r"\1", s)
158 """Sanitize docstrings and add custom failure explanation""" 165 s = _hexadecimal.sub(
"0", s)
171 """Sanitize messages and add custom failure explanation""" 177 """Hook to insert custom failure explanation""" 178 if hasattr(left,
"explanation"):
179 return left.explanation
182 @contextlib.contextmanager
184 """Suppress the desired exception""" 192 """Run the garbage collector twice (needed when running 193 reference counting tests with PyPy)""" 199 pytest.suppress = suppress
200 pytest.gc_collect = gc_collect
206 pybind11_tests.compiler_info
is not None 207 ),
"Please update pybind11_tests.cpp if this assert fails." 210 f
" {pybind11_tests.compiler_info}" 211 f
" {pybind11_tests.cpp_std}" 212 f
" {pybind11_tests.PYBIND11_INTERNALS_ID}"
bool hasattr(handle obj, handle name)
def __contains__(self, item)
def pytest_assertrepr_compare(op, left, right)
def _make_explanation(a, b)
def pytest_report_header(config)
def __call__(self, thing)
def _sanitize_docstring(thing)
def _sanitize_message(thing)
def __init__(self, capfd)
def __init__(self, sanitizer)
def __init__(self, string)