4Extends output capture as needed by pybind11: ignore constructors, optional unordered lines.
5Adds docstring and exceptions message sanitizers: ignore Python 2 vs 3 differences.
21_unicode_marker = re.compile(
r"u(\'[^\']*\')")
22_long_marker = re.compile(
r"([0-9])L")
23_hexadecimal = re.compile(
r"0x[0-9a-fA-F]+")
28 collect_ignore.append(
"test_async.py")
32 """For triple-quote strings"""
33 return textwrap.dedent(s.lstrip(
"\n").rstrip())
37 """For output which does not require specific line order"""
42 """Explanation for a failed assert -- the a and b arguments are List[str]"""
43 return [
"--- actual / +++ expected"] + [
44 line.strip(
"\n")
for line
in difflib.ndiff(a, b)
49 """Basic output post-processing and comparison"""
62 for line
in self.
string.strip().splitlines()
63 if not line.startswith(
"###")
74 """Custom comparison for output without strict line ordering"""
93 self.
capfd.readouterr()
112 return item
in self.
out
125 """Extended `capsys` with context manager and custom equality operators"""
151 s = s.replace(
"pybind11_tests.",
"m.")
152 s = s.replace(
"unicode",
"str")
153 s = _long_marker.sub(
r"\1", s)
154 s = _unicode_marker.sub(
r"\1", s)
166 """Sanitize docstrings and add custom failure explanation"""
173 s = _hexadecimal.sub(
"0", s)
179 """Sanitize messages and add custom failure explanation"""
185 """Hook to insert custom failure explanation"""
186 if hasattr(left,
"explanation"):
187 return left.explanation
190@contextlib.contextmanager
192 """Suppress the desired exception"""
200 """Run the garbage collector twice (needed when running
201 reference counting tests with PyPy)
"""
207 pytest.suppress = suppress
208 pytest.gc_collect = gc_collect
def __init__(self, capfd)
def __contains__(self, item)
def __exit__(self, *args)
def __init__(self, string)
def __call__(self, thing)
def __init__(self, sanitizer)
\rst Holds a reference to a Python object (with reference counting)
bool hasattr(handle obj, handle name)
def _sanitize_message(thing)
def pytest_assertrepr_compare(op, left, right)
def _sanitize_docstring(thing)
def _make_explanation(a, b)