From 429c8d0f0b0bd44af6b5837547695d0cb79fd4a2 Mon Sep 17 00:00:00 2001 From: Kyle Stewart <4b796c65+bitbucket@gmail.com> Date: Fri, 18 Mar 2016 01:13:51 -0700 Subject: Add polish to the error_on_ResourceWarning fixture. Removed the large and unnecessary traceback from the error printout. --- wheel/test/conftest.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/wheel/test/conftest.py b/wheel/test/conftest.py index bda2a98..d14cc47 100644 --- a/wheel/test/conftest.py +++ b/wheel/test/conftest.py @@ -8,9 +8,13 @@ import warnings import pytest @pytest.yield_fixture(scope='function', autouse=True) -def fail_on_ResourceWarning(): - """This fixture captures ResourceWarning's and raises an assertion error +def error_on_ResourceWarning(): + """This fixture captures ResourceWarning's and reports an "error" describing the file handles left open. + + This is shown regardless of how successful the test was, if a test fails + and leaves files open then those files will be reported. Ideally, even + those files should be closed properly after a test failure or exception. Since only Python 3 and PyPy3 have ResourceWarning's, this context will have no effect when running tests on Python 2 or PyPy. @@ -34,5 +38,8 @@ def fail_on_ResourceWarning(): warnings.simplefilter('always', ResourceWarning) # add filter yield # run tests in this context gc.collect() # run garbage collection (for pypy3) - # display the problematic filenames if any warnings were caught - assert not caught, '\n'.join((str(warning.message) for warning in caught)) + if not caught: + return + pytest.fail('The following file descriptors were not closed properly:\n' + + '\n'.join((str(warning.message) for warning in caught)), + pytrace=False) -- cgit v1.2.1