python icon indicating copy to clipboard operation
python copied to clipboard

ImportError while doing exercise

Open LindaK92 opened this issue 3 years ago • 3 comments

Hi all!

I hope this forum is the right place to put bugs.

I am doing excersise 2 (Lasagna) from Python and I get an import error, see below. I do not think I made a mistake with programming, because I have also looked at the solutions from the community and when I enter the exact same solution, it gives the same error. Now I cannot continue.

So how can this problem be fixed? Thank you very much!

" We received the following error when we ran your code:

ImportError while importing test module '.mnt.exercism-iteration.lasagna_test.py'. Hint: make sure your test modules.packages have valid Python names. Traceback: .mnt.exercism-iteration.lasagna_test.py:6: in from lasagna import (EXPECTED_BAKE_TIME, E ImportError: cannot import name 'EXPECTED_BAKE_TIME' from 'lasagna' (.mnt.exercism-iteration.lasagna.py)

During handling of the above exception, another exception occurred: .usr.local.lib.python3.10.importlib.init.py:126: in import_module return _bootstrap._gcd_import(name[level:], package, level) .mnt.exercism-iteration.lasagna_test.py:23: in raise ImportError("In your 'lasagna.py' file, we can not find or import the" E ImportError: In your 'lasagna.py' file, we can not find or import the function named 'EXPECTED_BAKE_TIME()'. Did you mis-name or forget to define it? "

LindaK92 avatar Oct 14 '22 07:10 LindaK92

Hi and welcome to Exercism! :wave:

Thanks for opening an issue :slightly_smiling_face:

  • If you are suggesting a new feature or an improvement to Exercism, please take a read of this post, which will likely result in a faster response.
  • If you are reporting a bug in the website, thank you! We are getting a lot of reports at the moment (which is great), but we triage and reply as soon as we can.
  • If you are requesting support, someone will help shortly.
  • For everything else, we will reply or triage your issue to the right repository soon.

github-actions[bot] avatar Oct 14 '22 07:10 github-actions[bot]

Hi @LindaK92 👋🏽

Thanks for filing this issue. As the Python track maintainer, i'd like to apologize -- that is bad logic in the test file, resulting in a bogus error message. We're using the logic for a missing function name, but it needs to be doing something different here. We'll try to get that bug fixed as quickly as we can.

However - mixed up in that erroneous message is a legitimate problem telling you that the test runner cannot import a name that it needs. It sadly happens to be lying about what kind of name it is trying to import. 🤦🏽‍♀️

The tests are looking for a constant named EXPECTED_BAKE_TIME, defined (usually) at the top of the file like so:


EXPECTED_BAKE_TIME = <replace with some numeric value you fill in here>
PREPARATION_TIME = <replace with some other numeric value you fill in here>


def bake_time_remaining(time):
    return <replace with code that uses the constants here>

def preparation_time_in_minutes(num_layers):
    return <replace with more code you fill in here>

For the quick test I did in my account on the website, if I don't have that first line defining the constant, I get the same stack trace you do. I think if you define (and use) that missing constant, the test runner will stop complaining.

Please let me know if that is not the case, and I'll try to help you further with getting unstuck (or help identify any additional bugs).

Again - apologies for the lying test runner. 😉

@iHiD or @ErikSchierboom -- could one of you transfer this to the python repo? Many thanks!

BethanyG avatar Oct 14 '22 23:10 BethanyG

🤖   🤖

Hi! 👋🏽 👋 Welcome to the Exercism Python Repo!

Thank you for opening an issue! 🐍  🌈 ✨


  •   If you are requesting support, we will be along shortly to help. (generally within 72 hours, often more quickly).
  •   Found a problem with tests, exercises or something else??  🎉
      ◦ We'll take a look as soon as we can & identify what work is needed to fix it. (generally within 72 hours).

​          ◦ If you'd also like to make a PR to fix the issue, please have a quick look at the Pull Requests doc.
             We  💙  PRs that follow our Exercism & Track contributing guidelines!

  •   Here because of an obvious (and small set of) spelling, grammar, or punctuation issues with one exercise,
      concept, or Python document?? 🌟 Please feel free to submit a PR, linking to this issue. 🎉
    ‼️  Please Do Not ‼️

    ​        ❗ Run checks on the whole repo & submit a bunch of PRs.
                  This creates longer review cycles & exhausts reviewers energy & time.
                  It may also conflict with ongoing changes from other contributors.
    ​        ❗ Insert only blank lines, make a closing bracket drop to the next line, change a word
                  to a synonym without obvious reason, or add trailing space that's not an EOL for the very end of text files.         ❗ Introduce arbitrary changes "just to change things" .

            ...These sorts of things are not considered helpful, and will likely be closed by reviewers.

  • For anything complicated or ambiguous, let's discuss things -- we will likely welcome a PR from you.
  • Here to suggest a feature or new exercise?? Hooray! Please keep in mind Chesterton's Fence.
    Thoughtful suggestions will likely result faster & more enthusiastic responses from maintainers.

💛  💙  While you are here... If you decide to help out with other open issues, you have our gratitude 🙌 🙌🏽.
Anything tagged with [help wanted] and without [Claimed] is up for grabs.
Comment on the issue and we will reserve it for you. 🌈 ✨

github-actions[bot] avatar Oct 15 '22 12:10 github-actions[bot]

I did the Hello_world test and encountered an error on submission as seen below. Kindly assist.

We received the following error when we ran your code: ImportError while importing test module '.mnt.exercism-iteration.hello_world_test.py'. Hint: make sure your test modules.packages have valid Python names. Traceback: .usr.local.lib.python3.10.importlib.init.py:126: in import_module return _bootstrap._gcd_import(name[level:], package, level) .mnt.exercism-iteration.hello_world_test.py:3: in from hello_world import ( E ImportError: cannot import name 'hello' from 'hello_world' (.mnt.exercism-iteration.hello_world.py)

bo1658a avatar Feb 23 '23 12:02 bo1658a

Hi @bo1658a 👋🏽

As stated in the auto-response for the last issue you opened on this repo, we would prefer if you first raised issues in our exercism forum, and not here in the Python repo.

The forum has many friendly people who would love to discuss and help students with issues they encounter. Another alternative is to use our CLI to upload your partial solution and request mentoring. A mentor can walk through your solution and point out where things might have gone wrong.

My reply in this forum post might also be helpful for you.

In the future, please don't comment on an unrelated exercise (this issue is in regards to Guido's Gorgeous Lasagna and not Hello World), as it creates confusion and noise.

Many thanks, and good luck with the exercise.

BethanyG avatar Feb 23 '23 19:02 BethanyG

@ErikSchierboom or @iHiD - any chance I could get eyes/approvals for the following related issues? I know it won't fix Hello World, but I do think it would help with the complaints we're getting on Lasagna. Many thanks!

#3339, #3344, and python-test-runner #110.

BethanyG avatar Feb 23 '23 20:02 BethanyG

Done

ErikSchierboom avatar Feb 24 '23 07:02 ErikSchierboom