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

Making the test run, when the script is run. #3762

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions exercises/practice/hello-world/hello_world_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ 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)

if __name__ == '__main__':
# Why is this if implanted?
# This prevents the contents within the if statement of this script from being run indirectly, when it is imported as a module in another script/module, or from recurring loops.
# So it runs only when you execute the test, i.e. this module/script.
# What does the naming mean?
# The name is __main__ because this is the default module that is run when the script is executed directly.
# If the script is run from another script, its name would be the name of the module it is imported as, i.e. hello_world_test.
unittest.main()