[Ellen's Alien Game] Tests are Blocked from Running in Editor & Locally Due to Function Import Error
See original GitHub issueDear community,
working on Ellen’s Alien Game, the tests do not run and I get this message:
We received the following error when we ran your code:
ImportError while importing test module ‘.mnt.exercism-iteration.classes_test.py’. Hint: make sure your test modules.packages have valid Python names. Traceback: .usr.local.lib.python3.9.importlib.init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) .mnt.exercism-iteration.classes_test.py:4: in <module> from classes import new_aliens_collection E ImportError: cannot import name ‘new_aliens_collection’ from ‘classes’ (.mnt.exercism-iteration.classes.py)
There is from classes import new_aliens_collection
in line 4 in classes_test.py
. Why is it there?
Issue Analytics
- State:
- Created a year ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Community solutions for Ellen's Alien Game in ... - Exercism
Explore other people's solutions to Ellen's Alien Game in Python, and learn how others have solved the exercise.
Read more >How to Fix PyCharm Import Error and Setup Your Interpreter
This will show you how to fix common pycharm import errors when trying to import python modules. Please watch through the entire video...
Read more >Changes to printed publication are marked in magenta ink.
Placement test scores no more than 3 years old and/or a transcript show- ing previous college course work. ASSET. ACCUPLACER.
Read more >Final Exam Flashcards - Quizlet
Study with Quizlet and memorize flashcards containing terms like YOUR SMARTPHONE'S RADIO ALARM SINGS YOU AWAKE., What Is Mass Communication?, ...
Read more >Pre-Incident Indicators of Terrorist Incidents: The Identification ...
frequently, crimes related to the maintenance of internal security. ... Terrorists and terrorist groups operate within the constraints and boundaries of ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bhagerty @lotruheawea @PaulT89 –
I’ve submitted PR #3058 to address some of these issues.
The first change is a
try-except
that “fences” the import. So now the stack track for a missingnew_aliens_collection()
should read similar to the following:The most important line there being the last one.
I’ve updated the exercise instructions to read:
7. Creating a List of Aliens
Ellen loves what you’ve done so far, but she has one more favor to ask. She would like a standalone (outside the
Alien()
class) function that creates alist
ofAlien()
objects, given a list of positions (astuples
).For example:
Finally, I’ve put a TODO in the stub:
If you can think of additional behaviors or issues, please comment here or in the PR. Many thanks for your comments and discussion! Once the PR is merged, I will close this issue.
I want to offer an opinion as a learner: I think that it is important to modify the test code so a learner who fails to stub out
new_aliens_collection
does not get the current error that is raised.The error currently raised does not give even a smart beginner, who can read some stack traces, a sufficient clue that the problem is in their code. The learner will see this:
This tells the learner that a name can’t be imported from a file they did not create, i.e.,
classes.py
. No beginner, even a smart one, is going to figure out that the problem is not actually inclasses.py
, but is in fact in the code they wrote.You could certainly solve this by providing a different error message—one that clues the learner in to the fact that the problem is not in
classes.py
but is in their code.But it would be better to test for the learner’s creation of
new_aliens_collection
separately. The only way I figured out what was going on was by reading this comment thread. Learners should not be expected to do that.