Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Guido's Gorgeous Lasagna] Fixed bug with lasagna ImportError message extraction. #110

Merged
merged 2 commits into from
Feb 25, 2023

Conversation

BethanyG
Copy link
Member

Adjusted the following code, starting on line 140:

    def pytest_exception_interact(self, node, call, report):
        """
        Catch the last exception handled in case the test run itself errors.
        """
        if report.outcome == "failed":
            excinfo = call.excinfo
            err = excinfo.getrepr(style="no", abspath=False)

            # trim off full traceback for first exercise to be friendlier and clearer
            if 'lasagna' in node.name and 'ImportError' in str(err.chain[0]):
                trace = err.chain[-2][0]
            else:
                trace = err.chain[-1][0]

            crash = err.chain[0][1]
            self.last_err = self._make_message(trace, crash)

previously, lasagna was capitalized, causing the code that strips the stack trace to fail. This has been fixed. Before, the student would see this for an import error in the UI:

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 <module>
    from lasagna import (EXPECTED_BAKE_TIME,
E   ImportError: cannot import name 'bake_time_remaining' 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 <module>
    raise ImportError("In your 'lasagna.py' file, we can not find or import the"
E   ImportError: MISSING CONSTANT --> We can not find or import the constant EXPECTED_BAKE_TIME in your 'lasagna.py' file.  Did you mis-name or forget to define it?

Now they will see the following in the UI (once the test file changes in the content repo are merged):

ImportError: 
   
   MISSING CONSTANT --> 
   We can not find or import the constant 'EXPECTED_BAKE_TIME' in your 'lasagna.py' file.
   Did you mis-name or forget to define it?

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! It might be worth adding a test case for this: https://github.com/exercism/python-test-runner/tree/main/test

@BethanyG
Copy link
Member Author

@ErikSchierboom -- good point! I added two: one for the constant, and one for a function name. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants