File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 7
7
import pytest
8
8
import textwrap
9
9
import difflib
10
+ import functools
10
11
import re
11
12
import sys
13
+ import trace
12
14
import contextlib
13
15
import platform
14
16
import gc
@@ -190,6 +192,25 @@ def gc_collect():
190
192
gc .collect ()
191
193
192
194
195
+ def traced (f ):
196
+ """Decorator to trace the output of a given function (or test case).
197
+
198
+ Example:
199
+
200
+ @pytest.traced
201
+ def test_something():
202
+ print("Hello")
203
+
204
+ """
205
+ tracer = trace .Trace (trace = 1 , count = 0 , ignoredirs = ["/usr" , sys .prefix ])
206
+
207
+ @functools .wraps (f )
208
+ def wrapped (* args , ** kwargs ):
209
+ return tracer .runfunc (f , * args , ** kwargs )
210
+
211
+ return wrapped
212
+
213
+
193
214
def pytest_configure ():
194
215
"""Add import suppression and test requirements to `pytest` namespace"""
195
216
try :
@@ -218,6 +239,7 @@ def pytest_configure():
218
239
pytest .unsupported_on_py2 = skipif (sys .version_info .major < 3 ,
219
240
reason = "unsupported on Python 2.x" )
220
241
pytest .gc_collect = gc_collect
242
+ pytest .traced = traced
221
243
222
244
223
245
def _test_import_pybind11 ():
You can’t perform that action at this time.
0 commit comments