#6437 defect new
twisted.trial.unittest.TestCase.flushWarnings may fail if run without .py files (with only .pyc or .pyo files)
|Reported by:||Jean-Paul Calderone||Owned by:||eddie|
branch-diff, diff-cov, branch-cov, buildbot
flushWarnings includes logic to filter warnings by their source. This includes some filename comparison logic:
# inspect.getabsfile(aFunction) sometimes returns a # filename which disagrees with the filename the warning # system generates. This seems to be because a # function's code object doesn't deal with source files # being renamed. inspect.getabsfile(module) seems # better (or at least agrees with the warning system # more often), and does some normalization for us which # is desirable. inspect.getmodule() is attractive, but # somewhat broken in Python < 2.6. See Python bug 4845. aModule = sys.modules[aFunction.__module__] filename = inspect.getabsfile(aModule) if filename != os.path.normcase(aWarning.filename): continue
inspect.getabsfile doesn't necessarily agree with the warning system either. If it discovers a ".pyc" filename and the corresponding ".py" file does not exist, it will return the ".pyc" file (if the ".py" file does exist, it strips the "c" off - which is why this isn't often a problem).
This is pretty easily reproduced. Write a
test_foo.py file like this:
import warnings from twisted.trial.unittest import TestCase class X(TestCase): def test_y(self): warnings.warn("Stuff") self.assertEqual(1, len(self.flushWarnings([self.test_y])))
run it with trial to convince yourself it works (and to write a .pyc file). Then delete it, but leave the .pyc file. Run it again with trial and the test will fail instead.
Change History (17)
comment:5 follow-up: 6 Changed 4 years ago by
|Keywords:||gsoc added; review removed|
|Owner:||set to eddie|