Closed jcmorrow closed 6 years ago
You're welcome! It's always nice to be appreciated.
Can you provide a little more context?
I'd love to help, but I don't really have a whole lot to go on.
Hey! Yes, totally, I should have included more context.
OS: Mac OS High Sierra (10.13.1)
Python: 2.7
Flask: 0.12.2
Output of green -V
: Green 2.12.0, Coverage 4.4.2, Python 2.7.0
Full output from running green
command:
Traceback (most recent call last):
File "/usr/local/opt/pyenv/versions/2.7/bin/green", line 11, in <module>
sys.exit(main())
File "/usr/local/opt/pyenv/versions/2.7/lib/python2.7/site-packages/green/cmdline.py", line 22, in main
from green.loader import GreenTestLoader, getCompletions
File "/usr/local/opt/pyenv/versions/2.7/lib/python2.7/site-packages/green/loader.py", line 16, in <module>
from green.suite import GreenTestSuite
File "/usr/local/opt/pyenv/versions/2.7/lib/python2.7/site-packages/green/suite.py", line 6, in <module>
from unittest.suite import _call_if_exists, _DebugResult, _isnotsuite, TestSuite
ImportError: cannot import name _call_if_exists
I haven't gotten past loading green
so I don't think the source would be particularly helpful, but I'm happy to share anything that might help.
Wait, Python 2.7.0 on High Sierra? There's your problem. Version 2.7.0 was released in 2010!!! I think you need to use at least 2.7.4, which was released in 2013. I highly suggest using the most up-to-date version (2.7.14 at the moment), as most updates contain security and bug fixes.
Aha! Sorry, I've just started working in Python, I will go upgrade my everything 😨
Wait! If you don't have a special reason to use a custom Python...don't! macOS ships with a recent version of Python 2.7.x by default. It's already there! Just uninstall your custom installation and it should work fine.
If you do need to install your own version of Python, I highly recommend using homebrew to install and manage custom versions of Python.
Hey folks! Thank you for your hard work!
Problem
This test runner looks neat, I'd like to give it a whirl, but I keep getting an import error
cannot import name _call_if_exists
Root Cause
I've done a bit of digging, this line is definitely the culprit, and from what I can tell it is a valid import error.I was completely wrong. This method is definitely defined in the python 2.7 source code. So, now I have a new question: why can't I import it? Possible hint: it works from the_call_if_exists
doesn't appear in the python 2.7 or 3.6 source code (at least, not that I could find, I'm not an expert python source diver quite yet). It seems like it maybe does exist in Django? , so perhaps that's why others are not hitting this error?python3
repl but not from thepython2
repl.Proposed Solution
What if, instead of importing it, we defined that function, just as Django appears to do? Thoughts? If that's a good solution I'd be happy to PR it.Cheers and thanks again!