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

[Hello World] Added Hello World to ImportError Message Extraction #111

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def pytest_exception_interact(self, node, call, report):
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]):
# trim off full traceback for first two exercises to be friendlier and clearer
if ('lasagna' in node.name or 'hello_world' in node.name) and 'ImportError' in str(err.chain[0]):
trace = err.chain[-2][0]
else:
trace = err.chain[-1][0]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
print("Hello, World!")

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest

try:
from hello_world import (
hello,
)

except ImportError as import_fail:
message = import_fail.args[0].split("(", maxsplit=1)
item_name = import_fail.args[0].split()[3]

item_name = item_name[:-1] + "()'"

# pylint: disable=raise-missing-from
raise ImportError(
"\n\nMISSING FUNCTION --> In your 'hello_world.py' file, we can not find or import the"
f" function named {item_name}. \nThe tests for this first exercise expect a function that"
f' returns the string "Hello, World!"'
f'\n\nDid you use print("Hello, World!") instead?'
) from None


class HelloWorldTest(unittest.TestCase):
def test_say_hi(self):
msg = "\n\nThis test expects a return of the string 'Hello, World!' \nDid you use print('Hello, World!') by mistake?"
self.assertEqual(hello(), "Hello, World!", msg=msg)
6 changes: 6 additions & 0 deletions test/example-hello-world-function-import-error/results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 3,
"status": "error",
"message": "ImportError: \n\nMISSING FUNCTION --> In your 'hello_world.py' file, we can not find or import the function named 'hello_world()'. \nThe tests for this first exercise expect a function that returns the string \"Hello, World!\"\n\nDid you use print(\"Hello, World!\") instead?",
"tests": []
}