summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Stewart <4b796c65+bitbucket@gmail.com>2016-03-18 01:13:51 -0700
committerKyle Stewart <4b796c65+bitbucket@gmail.com>2016-03-18 01:13:51 -0700
commit429c8d0f0b0bd44af6b5837547695d0cb79fd4a2 (patch)
treefaddac7c69999b5efedf4f4157ed6e817d4fa755
parent7d5fe9ae5cb8177171cd67f5728c2b6f35f5703b (diff)
downloadwheel-429c8d0f0b0bd44af6b5837547695d0cb79fd4a2.tar.gz
Add polish to the error_on_ResourceWarning fixture.strict-resource-testing
Removed the large and unnecessary traceback from the error printout.
-rw-r--r--wheel/test/conftest.py15
1 files 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)