2 """pytest configuration 4 Extends output capture as needed by pybind11: ignore constructors, optional unordered lines. 5 Adds 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"] + [line.strip(
'\n')
for line
in difflib.ndiff(a, b)]
47 """Basic output post-processing and comparison""" 57 a = [line
for line
in self.string.strip().splitlines()
if not line.startswith(
"###")]
67 """Custom comparison for output without strict line ordering""" 85 self.capfd.readouterr()
89 self.
out, self.
err = self.capfd.readouterr()
104 return item
in self.
out 117 """Extended `capsys` with context manager and custom equality operators""" 143 s = s.replace(
"pybind11_tests.",
"m.")
144 s = s.replace(
"unicode",
"str")
145 s = _long_marker.sub(
r"\1", s)
146 s = _unicode_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
bool hasattr(handle obj, handle name)
def __contains__(self, item)
def pytest_assertrepr_compare(op, left, right)
def _make_explanation(a, b)
def __call__(self, thing)
def _sanitize_docstring(thing)
def _sanitize_message(thing)
def __init__(self, capfd)
def __init__(self, sanitizer)
def __init__(self, string)