conftest.py (11986:c12e4625ab56) | conftest.py (12037:d28054ac6ec9) |
---|---|
1"""pytest configuration 2 3Extends output capture as needed by pybind11: ignore constructors, optional unordered lines. 4Adds docstring and exceptions message sanitizers: ignore Python 2 vs 3 differences. 5""" 6 7import pytest 8import textwrap 9import difflib 10import re 11import sys 12import contextlib | 1"""pytest configuration 2 3Extends output capture as needed by pybind11: ignore constructors, optional unordered lines. 4Adds docstring and exceptions message sanitizers: ignore Python 2 vs 3 differences. 5""" 6 7import pytest 8import textwrap 9import difflib 10import re 11import sys 12import contextlib |
13import platform 14import gc |
|
13 14_unicode_marker = re.compile(r'u(\'[^\']*\')') 15_long_marker = re.compile(r'([0-9])L') 16_hexadecimal = re.compile(r'0x[0-9a-fA-F]+') 17 18 19def _strip_and_dedent(s): 20 """For triple-quote strings""" --- 75 unchanged lines hidden (view full) --- 96 return Unordered(self.out) 97 98 @property 99 def stderr(self): 100 return Output(self.err) 101 102 103@pytest.fixture | 15 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]+') 19 20 21def _strip_and_dedent(s): 22 """For triple-quote strings""" --- 75 unchanged lines hidden (view full) --- 98 return Unordered(self.out) 99 100 @property 101 def stderr(self): 102 return Output(self.err) 103 104 105@pytest.fixture |
104def capture(capfd): 105 """Extended `capfd` with context manager and custom equality operators""" 106 return Capture(capfd) | 106def capture(capsys): 107 """Extended `capsys` with context manager and custom equality operators""" 108 return Capture(capsys) |
107 108 109class SanitizedString(object): 110 def __init__(self, sanitizer): 111 self.sanitizer = sanitizer 112 self.string = "" 113 self.explanation = [] 114 --- 56 unchanged lines hidden (view full) --- 171def suppress(exception): 172 """Suppress the desired exception""" 173 try: 174 yield 175 except exception: 176 pass 177 178 | 109 110 111class SanitizedString(object): 112 def __init__(self, sanitizer): 113 self.sanitizer = sanitizer 114 self.string = "" 115 self.explanation = [] 116 --- 56 unchanged lines hidden (view full) --- 173def suppress(exception): 174 """Suppress the desired exception""" 175 try: 176 yield 177 except exception: 178 pass 179 180 |
181def gc_collect(): 182 ''' Run the garbage collector twice (needed when running 183 reference counting tests with PyPy) ''' 184 gc.collect() 185 gc.collect() 186 187 |
|
179def pytest_namespace(): 180 """Add import suppression and test requirements to `pytest` namespace""" 181 try: 182 import numpy as np 183 except ImportError: 184 np = None 185 try: 186 import scipy 187 except ImportError: 188 scipy = None 189 try: 190 from pybind11_tests import have_eigen 191 except ImportError: 192 have_eigen = False | 188def pytest_namespace(): 189 """Add import suppression and test requirements to `pytest` namespace""" 190 try: 191 import numpy as np 192 except ImportError: 193 np = None 194 try: 195 import scipy 196 except ImportError: 197 scipy = None 198 try: 199 from pybind11_tests import have_eigen 200 except ImportError: 201 have_eigen = False |
202 pypy = platform.python_implementation() == "PyPy" |
|
193 194 skipif = pytest.mark.skipif 195 return { 196 'suppress': suppress, 197 'requires_numpy': skipif(not np, reason="numpy is not installed"), 198 'requires_scipy': skipif(not np, reason="scipy is not installed"), 199 'requires_eigen_and_numpy': skipif(not have_eigen or not np, 200 reason="eigen and/or numpy are not installed"), 201 'requires_eigen_and_scipy': skipif(not have_eigen or not scipy, 202 reason="eigen and/or scipy are not installed"), | 203 204 skipif = pytest.mark.skipif 205 return { 206 'suppress': suppress, 207 'requires_numpy': skipif(not np, reason="numpy is not installed"), 208 'requires_scipy': skipif(not np, reason="scipy is not installed"), 209 'requires_eigen_and_numpy': skipif(not have_eigen or not np, 210 reason="eigen and/or numpy are not installed"), 211 'requires_eigen_and_scipy': skipif(not have_eigen or not scipy, 212 reason="eigen and/or scipy are not installed"), |
213 'unsupported_on_pypy': skipif(pypy, reason="unsupported on PyPy"), 214 'gc_collect': gc_collect |
|
203 } 204 205 206def _test_import_pybind11(): 207 """Early diagnostic for test module initialization errors 208 209 When there is an error during initialization, the first import will report the 210 real error while all subsequent imports will report nonsense. This import test --- 17 unchanged lines hidden --- | 215 } 216 217 218def _test_import_pybind11(): 219 """Early diagnostic for test module initialization errors 220 221 When there is an error during initialization, the first import will report the 222 real error while all subsequent imports will report nonsense. This import test --- 17 unchanged lines hidden --- |