3Extends output capture as needed by pybind11: ignore constructors, optional unordered lines.
4Adds docstring and exceptions message sanitizers.
27@pytest.fixture(scope="session", autouse=True)
39 multiprocessing.set_start_method(
"forkserver")
42_long_marker = re.compile(
r"([0-9])L")
43_hexadecimal = re.compile(
r"0x[0-9a-fA-F]+")
50 """For triple-quote strings"""
51 return textwrap.dedent(s.lstrip(
"\n").rstrip())
55 """For output which does not require specific line order"""
60 """Explanation for a failed assert -- the a and b arguments are List[str]"""
61 return [
"--- actual / +++ expected"] + [
62 line.strip(
"\n")
for line
in difflib.ndiff(a, b)
67 """Basic output post-processing and comparison"""
80 for line
in self.
string.strip().splitlines()
81 if not line.startswith(
"###")
92 """Custom comparison for output without strict line ordering"""
111 self.
capfd.readouterr()
130 return item
in self.
out
143 """Extended `capsys` with context manager and custom equality operators"""
169 s = s.replace(
"pybind11_tests.",
"m.")
170 s = _long_marker.sub(
r"\1", s)
182 """Sanitize docstrings and add custom failure explanation"""
189 s = _hexadecimal.sub(
"0", s)
195 """Sanitize messages and add custom failure explanation"""
201 """Hook to insert custom failure explanation"""
202 if hasattr(left,
"explanation"):
203 return left.explanation
206@contextlib.contextmanager
208 """Suppress the desired exception"""
216 """Run the garbage collector twice (needed when running
217 reference counting tests with PyPy)
"""
223 pytest.suppress = suppress
224 pytest.gc_collect = gc_collect
230 pybind11_tests.compiler_info
is not None
231 ),
"Please update pybind11_tests.cpp if this assert fails."
234 f
" {pybind11_tests.compiler_info}"
235 f
" {pybind11_tests.cpp_std}"
236 f
" {pybind11_tests.PYBIND11_INTERNALS_ID}"
237 f
" PYBIND11_SIMPLE_GIL_MANAGEMENT={pybind11_tests.PYBIND11_SIMPLE_GIL_MANAGEMENT}"
def __init__(self, capfd)
def __contains__(self, item)
def __exit__(self, *args)
def __init__(self, string)
def __call__(self, thing)
def __init__(self, sanitizer)
bool hasattr(handle obj, handle name)
def _sanitize_message(thing)
def pytest_assertrepr_compare(op, left, right)
def always_forkserver_on_unix()
def _sanitize_docstring(thing)
def _make_explanation(a, b)
def pytest_report_header(config)