[Error Handling]: ImportError while importing test module (Error-Handling Messaging & Exercises)
See original GitHub issueGood day. I first offer the obligatory “I’m not GitHub-savvy” apology. I did look for an answer as prescribed here, following steps in subheading Opening an Issue. But I have not seen anything. I’ve seen some fixes on Stack Overflow. But they make no sense to me. Please don’t crush me if I’m doing this wrong.
I’m working on a new linux install. On my previous installation, I ran pytest successfully many times (28 to be precise). With this new installation, I’ve run it once successfully on exercise Twelve Days of Christmas. It’s giving me this error now:
$ /home/dan/.local/bin/pytest meetup_test.py
============================= test session starts ==============================
platform linux -- Python 3.8.5, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/dan/exercism/python/meetup
collected 0 items / 1 error
==================================== ERRORS ====================================
_______________________ ERROR collecting meetup_test.py ________________________
ImportError while importing test module '/home/dan/exercism/python/meetup/meetup_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
meetup_test.py:4: in <module>
from meetup import meetup, MeetupDayException
E ImportError: cannot import name 'MeetupDayException' from 'meetup' (/home/dan/exercism/python/meetup/meetup.py)
=========================== short test summary info ============================
ERROR meetup_test.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.09s ===============================
$
I tried removing the meetup directory and re-downloading from the CLI. I get this error no matter what the contents of meetup.py are. So, I’m guessing that I have some issue either with they way pytest is configured or with my meetup_pytest file.
Any assistance greatly appreciated.
Thank you so much. Dan.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
@BethanyG I would like to leave this open as a reference issue until we’ve made the changes we talked about.
Hi @dan9731 👋
Since @NobbZ is in CET, I’m picking this up. (I’m in PST). Apologies - the test file for this exercise appears to have been updated since you last worked on/ran it, and it is indeed expecting you to define a
MeetupDayException
class.To get around this (temporarily) you can add the following to the top of your
meetup_test.py
file, directly below the line that saysfrom meetup import meetup, MeetupDayException
, and removeMeetupDayException
from the import line, so that the two look like this:That way, you can run and work on any tests that might be failing right now for you. When I ran your code, it looks as though 7 of the 90 tests have failed – mostly for
ValueErrors
where the day is out of range for the month.To fully pass all the tests without the test file modification, you will need to make a custom
MeetupDayException
Class by subclassingException
. Something along the lines of this:As you can see, I’ve made a function that is named
meetup()
that calls a function calledmeetup_check()
(which is what I renamed yourmeetup()
function to). You probably want to be more targeted in the errors you catch/raise – so you can raise the exception specifically/directly asValueErrors
orIndexErrors
get caught within your code – but this was quicker for me to demonstrate.For more detail on how to create/customize and handle errors, take a look at the docs here.
Please let us know if this works for you, and if you have any additional questions or issues.
Best, Bethany