exercism / python

Exercism exercises in Python.
https://exercism.org/tracks/python
MIT License
1.92k stars 1.29k forks source link

Missing init code for test scripts #2717

Closed shumashv1 closed 3 years ago

shumashv1 commented 3 years ago

Test scripts import both pytest and unittest. I run code locally in the Spyder GUI, and tests don't execute until I add initiator lines. If I add an initiator to the last lines of the script (as previous test scripts have done) as follows:

if name == "main": pytest.main()

-or-

if name == "main": unittest.main()

the tests run. Running the tests from the command line also works with: python -m unittest _test.py -or- python -m pytest _test.py

github-actions[bot] commented 3 years ago

🤖   🤖

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

Thank you for opening an issue! 🐍  🌈 ✨


​           - If you'd also like to make a PR to fix the issue after discussing it,
             We  💙  PRs that follow our Exercism & Track contributing guidelines!

​        ❗ 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.
             For anything complicated or ambiguous, let's discuss things -- we will likely welcome a PR from you.

​        ❗ Please keep in mind that inserting only blank lines, making a closing bracket drop to the next line, changing a
             word to a synonym without obvious reason, adding trailing space that's not a EOL for the very end of text files,
             and other "changes just to change things" are not considered helpful, and will likely be closed by reviewers.


💙  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. 🌈 ✨

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.

IsaacG commented 3 years ago

This is working as intended.

Per the Python testing docs, you should be able to configure your editor to run tests using pytest or python3 -m pytest. That's the intended workflow.

Running the test file directly as an executable script is not the intended or supported workflow. The Python maintainers have been explicitly removing the if __name__ == "__main__" stanzas from the Python test files as we do not want students going that route.

shumashv1 commented 3 years ago

OK, I’ll buy that, but when I go to the Testing docs link and attempt to look into Tools, I get this:

https://exercism.org/docs/tracks/python/TOOLS.md @.*** Not very helpful.

From: Isaac Good @.> Sent: Tuesday, November 2, 2021 3:17 PM To: exercism/python @.> Cc: shumashv1 @.>; Author @.> Subject: Re: [exercism/python] Missing init code for test scripts (Issue #2717)

This is working as intended.

Per the Python testing docshttps://exercism.org/docs/tracks/python/tests, you should be able to configure your editor to run tests using pytest or python3 -m pytest. That's the intended workflow.

Running the test file directly as an executable script is not the intended or supported workflow. The Python maintainers have been explicitly removing the if name == "main" stanzas from the Python test files as we do not want students going that route.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/exercism/python/issues/2717#issuecomment-958173160, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAO7WADMPBAGX7YVJ7RY2L3UKBPNPANCNFSM5HGXGH2A. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

IsaacG commented 3 years ago

You're absolutely right. Thanks for calling that out. I filed https://github.com/exercism/python/issues/2721 to fix that.

You can view the TOOLS.md directly in Github in the meanwhile.

BethanyG commented 3 years ago

@shumashv1

The details in this issue may be of help. Spyder actually has an add-in that will allow you to run pytest files. However, if you have Spyder 5, I don't know that the plugin works. The other details in the issue address various ways to invoke Pytest from iPython/Spyder.

We'll get the linking issues with the testing/tooling docs fixed shortly.

shumashv1 commented 3 years ago

Thanks for the response. Very helpful.

From: BethanyG @.> Sent: Tuesday, November 2, 2021 9:11 PM To: exercism/python @.> Cc: shumashv1 @.>; Mention @.> Subject: Re: [exercism/python] Missing init code for test scripts (Issue #2717)

@shumashv1 https://github.com/shumashv1

The details in this issue may be of help. Spyder actually has an add-in that will allow you to run pytest files. However, if you have Spyder 5, I don't know that the plugin works. The other details in the issue address various ways to invoke Pytest from iPython/Spyder. exercism/exercism#5791 https://github.com/exercism/exercism/issues/5791 .

We'll get the linking issues with the testing/tooling docs fixed shortly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/exercism/python/issues/2717#issuecomment-958618899 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO7WAFSU6L5UFAVXVJVAFLUKCY5LANCNFSM5HGXGH2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . https://github.com/notifications/beacon/AAO7WACQHE4WNJ2RMOKFUWLUKCY5LA5CNFSM5HGXGH2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHERV2EY.gif

shumashv1 commented 3 years ago

Thanks. Very helpful.

From: BethanyG @.> Sent: Tuesday, November 2, 2021 9:11 PM To: exercism/python @.> Cc: shumashv1 @.>; Mention @.> Subject: Re: [exercism/python] Missing init code for test scripts (Issue #2717)

@shumashv1 https://github.com/shumashv1

The details in this issue may be of help. Spyder actually has an add-in that will allow you to run pytest files. However, if you have Spyder 5, I don't know that the plugin works. The other details in the issue address various ways to invoke Pytest from iPython/Spyder. exercism/exercism#5791 https://github.com/exercism/exercism/issues/5791 .

We'll get the linking issues with the testing/tooling docs fixed shortly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/exercism/python/issues/2717#issuecomment-958618899 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO7WAFSU6L5UFAVXVJVAFLUKCY5LANCNFSM5HGXGH2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . https://github.com/notifications/beacon/AAO7WACQHE4WNJ2RMOKFUWLUKCY5LA5CNFSM5HGXGH2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHERV2EY.gif

BethanyG commented 3 years ago

@shumashv1 - very happy that helped!

I am going to close this issue as resolved. Please feel free to open another, should you need help, have a question, or spot a bug. 🌟

The publishing/links problem you encountered is logged as issue #2721 .