green
green copied to clipboard
Confusing error when I have errors in source code
I had a file with:
import functools
from typings import List
...
Note that typings is an invalid import. It should be typing
Trying to run green I got:
❯ poetry run green extract/lib/test/test_rules.py
E
Error in .unittest.loader
TypeError: Test loader returned an un-runnable object. Is "unittest.loader" importable from your current location? Maybe you forgot an __init__.py in your directory? Unrunnable object looks like: None of type <class 'NoneType'> with dir ['__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
Ran 1 test in 0.024s using 8 processes
FAILED (errors=1)
The error doesn't give a hint of what the issue is.
Then I tried pytest:
❯ poetry run pytest extract/lib/test/test_rules.py
...
========================================================================================================================================== ERRORS ==========================================================================================================================================
_____________________________________________________________________________________________________________________ ERROR collecting extract/lib/test/test_rules.py ______________________________________________________________________________________________________________________
ImportError while importing test module '/home/sebastian/Source/staxio/cost-spike-1/extract_py/extract/lib/test/test_rules.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
extract/lib/test/test_rules.py:1: in <module>
import extract.lib.rules as rules
extract/lib/rules.py:2: in <module>
from typings import List
E ModuleNotFoundError: No module named 'typings'
================================================================================================================================= short test summary info ==================================================================================================================================
ERROR extract/lib/test/test_rules.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================================================================================== 1 error in 0.07s =====================================================================================================================================
Note ModuleNotFoundError: No module named 'typings'
Would be great if green could show the error.
Thanks
Can you please provide:
- The output of
green -V - The name and version of your Operating System?
green -V Green 3.4.1, Coverage 6.3.2, Python 3.9.12
I tried this in PopOS (Ubuntu 21.10) and MacOS (Intel mac) with the same result.
This only happens when you try to run one test. e.g. green test/test_x.py
If I try to run the whole test suite it shows the proper error.
This only happens when you try to run one test. e.g.
green test/test_x.pyIf I try to run the whole test suite it shows the proper error.
Ah! That's extremely helpful information, thanks!
FYI, I spent a couple hours looking into this, and it's quite tricky to fix without breaking other features. I plan to take another look at it sometime.