You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a test file raises an ImportError (e.g. because it fails to import a function from another module), trial reports the ImportError correctly while running the whole the test suite, but reports an AttributeError stating that the test file doesn't exist while trying to run the test file directly.
Running the whole test suite using trial3 package (or trial3 package.test) returns the correct error:
$ PYTHONPATH=`pwd` trial3 package
package
test
test_file ... [ERROR]
===============================================================================
[ERROR]
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/twisted/trial/runner.py", line 508, in loadPackage
module = modinfo.load()
File "/usr/lib/python3/dist-packages/twisted/python/modules.py", line 392, in load
return self.pathEntry.pythonPath.moduleLoader(self.name)
File "/usr/lib/python3/dist-packages/twisted/python/reflect.py", line 308, in namedAny
topLevelPackage = _importAndCheckStack(trialname)
File "/usr/lib/python3/dist-packages/twisted/python/reflect.py", line 255, in _importAndCheckStack
reraise(excValue, excTraceback)
File "/home/wolf/tribug/package/test/test_file.py", line 1, in <module>
from package.file import func
builtins.ImportError: cannot import name 'func'
package.test.test_file
-------------------------------------------------------------------------------
Ran 1 tests in 0.210s
FAILED (errors=1)
Trying to run the tests with trial3 package.test.test_file returns an AttributeError incorrectly stating that the test file doesn't exist:
$ PYTHONPATH=`pwd` trial3 package.test.test_file
package
test
test_file ... [ERROR]
===============================================================================
[ERROR]
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/twisted/trial/runner.py", line 781, in loadByName
return self.suiteFactory([self.findByName(name, recurse=recurse)])
File "/usr/lib/python3/dist-packages/twisted/trial/runner.py", line 720, in findByName
raise AttributeError("{} does not exist.".format(name))
builtins.AttributeError: package.test.test_file does not exist.
package.test.test_file
-------------------------------------------------------------------------------
Ran 1 tests in 0.209s
FAILED (errors=1)
To verify that the test file exists and that trial can find it, just define func in file.py, and run the same command again:
#!CommitTicketReference repository="" revision="ab6156fa761832b6711b2484665cabd07906f491"
Merge pull request #1143 from twisted/9628-trial3-importerror
[9628] Fix trial3 not knowing the difference between ImportErrors and modules not existing
Author: hawkowl
Reviewers: markrwilliams
Fixes: ticket:9628
If a test file raises an
ImportError
(e.g. because it fails to import a function from another module), trial reports theImportError
correctly while running the whole the test suite, but reports anAttributeError
stating that the test file doesn't exist while trying to run the test file directly.Setup to reproduce the issue:
Running the whole test suite using
trial3 package
(ortrial3 package.test
) returns the correct error:Trying to run the tests with
trial3 package.test.test_file
returns anAttributeError
incorrectly stating that the test file doesn't exist:To verify that the test file exists and that trial can find it, just define
func
infile.py
, and run the same command again:Tested on Ubuntu 18.04 with Twisted version 17.9.0.
Searchable metadata
The text was updated successfully, but these errors were encountered: