Skip to content

Commit 864bad2

Browse files
committed
If arraydiff is not enabled, still intercept the return value
This is to prevent a pytest warning or error
1 parent 04e365c commit 864bad2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pytest_arraydiff/plugin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ def pytest_configure(config):
221221
reference_dir=reference_dir,
222222
generate_dir=generate_dir,
223223
default_format=default_format))
224+
else:
225+
config.pluginmanager.register(ArrayInterceptor(config))
224226

225227

226228
def generate_test_name(item):
@@ -359,3 +361,23 @@ def pytest_runtest_call(self, item):
359361
FORMATS[file_format].write(os.path.abspath(os.path.join(self.generate_dir, filename)), array, **write_kwargs)
360362

361363
pytest.skip("Skipping test, since generating data")
364+
365+
366+
class ArrayInterceptor:
367+
"""
368+
This is used in place of ArrayComparison when the array comparison option is not used,
369+
to make sure that we still intercept arrays returned by tests.
370+
"""
371+
372+
def __init__(self, config):
373+
self.config = config
374+
self.return_value = {}
375+
376+
@pytest.hookimpl(hookwrapper=True)
377+
def pytest_runtest_call(self, item):
378+
379+
if item.get_closest_marker('array_compare') is not None:
380+
wrap_array_interceptor(self, item)
381+
382+
yield
383+
return

0 commit comments

Comments
 (0)