CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
786 stars 74 forks source link

cannot import name _call_if_exists #175

Closed jcmorrow closed 6 years ago

jcmorrow commented 6 years ago

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. _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? 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 python3 repl but not from the python2 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!

CleanCut commented 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.

jcmorrow commented 6 years ago

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.

CleanCut commented 6 years ago

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.

jcmorrow commented 6 years ago

Aha! Sorry, I've just started working in Python, I will go upgrade my everything 😨

CleanCut commented 6 years ago

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.