Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trial3 reports "AttributeError: test_file does not exist" when an ImportError is raised by test_file.py #9628

Closed
twisted-trac opened this issue Apr 22, 2019 · 3 comments

Comments

@twisted-trac
Copy link

ezio-melotti's avatar @ezio-melotti reported
Trac ID trac#9628
Type defect
Created 2019-04-22 15:20:55Z

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.

Setup to reproduce the issue:

mkdir  package  package/test
touch  package/file.py  package/__init__.py  package/test/__init__.py
echo 'from package.file import func' > package/test/test_file.py

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:

$ echo 'def func(): pass' > package/file.py 
$ PYTHONPATH=`pwd` trial3 package.test.test_file

-------------------------------------------------------------------------------

PASSED

Tested on Ubuntu 18.04 with Twisted version 17.9.0.

Searchable metadata
trac-id__9628 9628
type__defect defect
reporter__ezio_melotti ezio-melotti
priority__normal normal
milestone__Python_3_x Python-3.x
branch__ 
branch_author__ 
status__closed closed
resolution__fixed fixed
component__trial trial
keywords__None None
time__1555946455542614 1555946455542614
changetime__1568021363729925 1568021363729925
version__None None
owner__Mark_Williams__mrw_____ Mark Williams <mrw@...>

@twisted-trac
Copy link
Author

hawkowl's avatar @hawkowl commented

PR: #1143

@twisted-trac
Copy link
Author

markrwilliams's avatar @markrwilliams set owner to @markrwilliams
@markrwilliams set status to closed

In changeset ab6156f

#!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

@twisted-trac
Copy link
Author

ezio-melotti's avatar @ezio-melotti commented

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants