question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Ellen's Alien Game] Tests are Blocked from Running in Editor & Locally Due to Function Import Error

See original GitHub issue

Dear 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:closed
  • Created a year ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
BethanyGcommented, May 21, 2022

@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 missing new_aliens_collection() should read similar to the following:

 ImportError while importing test module '.solution.classes_test.py'.
 Hint: make sure your test modules.packages have valid Python names.
 Traceback:
 solution.classes_test.py:6: in <module>
    from classes import new_aliens_collection
E   ImportError: cannot import name 'new_aliens_collection' from 'classes' (.solution.classes.py)

The above exception was the direct cause of the following exception:
.usr.local.lib.python3.9.importlib.__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level).solution.classes_test.py:8: in <module>
    raise ImportError(\"We tried to import the new_aliens_collection() function from the classes.py file, \"

E   ImportError: We tried to import the new_aliens_collection() function, but could not find it. Did you remember to create it?"

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 a list of Alien() objects, given a list of positions (as tuples).

For example:

>>> alien_start_positions = [(4, 7), (-1, 0)]
>>> aliens = new_aliens_collection(alien_start_positions)
...
>>> for alien in aliens:
    	print(alien.x_coordinate, alien.y_coordinate)
(4, 7)
(-1, 0)


Finally, I’ve put a TODO in the stub:

"""Solution to Ellen's Alien Game exercise."""


class Alien:
    """Create an Alien object with location x_coordinate and y_coordinate.

    Attributes
    ----------
    (class)total_aliens_created: int
    x_coordinate: int - Position on the x-axis.
    y_coordinate: int - Position on the y-axis.
    health: int - Amount of health points.

    Methods
    -------
    hit(): Decrement Alien health by one point.
    is_alive(): Return a boolean for if Alien is alive (if health is > 0).
    teleport(new_x_coordinate, new_y_coordinate): Move Alien object to new coordinates.
    collision_detection(other): Implementation TBD.
    """

    pass


#TODO:  create the new_aliens_collection() function below to call your Alien class with a list of coordinates.

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.

0reactions
bhagertycommented, May 14, 2022

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:

ImportError: cannot import name 'new_aliens_collection' from 'classes' (.mnt.exercism-iteration.classes.py)

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 in classes.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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found