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

bpo-46425: fix direct invocation of asyncio tests #30725

Merged
merged 1 commit into from Jan 22, 2022

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Jan 20, 2022

Right now some tests in test_asyncio are suitable to be executed directly as python Lib/test/test_asyncio/test_X.py and some are only executable with -m test or -m Lib/test/test_asyncio.

This does not look good to me.

So, I've fixed several tests modules in test_asyncio when invoked directly as python module_name.py

There were two major problems:

  • relative imports
  • missing unittest.main() call

The best way to illustrate this problem is to show Lib/test/test_asyncio/test_runners.py:

Step 1. No changes.

» ./python.exe Lib/test/test_asyncio/test_runners.py
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython/Lib/test/test_asyncio/test_runners.py", line 5, in <module>
    from . import utils as test_utils
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: attempted relative import with no known parent package

Step 2. Fixed relative import.

» ./python.exe Lib/test/test_asyncio/test_runners.py

(nothing happens)

Step 3. With unottest.main():

» ./python.exe Lib/test/test_asyncio/test_runners.py
........
----------------------------------------------------------------------
Ran 8 tests in 0.018s

OK

CC @corona10 as my mentor.

https://bugs.python.org/issue46425

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

Is there a reason that you run tests like scripts?

@sobolevn
Copy link
Member Author

sobolevn commented Jan 22, 2022

Is there a reason that you run tests like scripts?

I just click "Run file" in my IDE, it is the easiest thing to do when testing something.
And since it is supported by if __name__ == '__main__': unittest.main(), I think others might do the same / similar thing.

Copy link
Contributor

@asvetlov asvetlov left a comment

Historically unittest.main() was added on demand during unit tests debugging.
Thanks for spreading it everywhere.

@asvetlov asvetlov merged commit 5a53400 into python:main Jan 22, 2022
11 checks passed
@miss-islington
Copy link
Contributor

miss-islington commented Jan 22, 2022

Thanks @sobolevn for the PR, and @asvetlov for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒🤖

@bedevere-bot
Copy link

bedevere-bot commented Jan 22, 2022

@asvetlov: Please replace # with GH- in the commit message next time. Thanks!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 22, 2022
(cherry picked from commit 5a53400)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-bot
Copy link

bedevere-bot commented Jan 22, 2022

GH-30782 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 22, 2022
(cherry picked from commit 5a53400)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-bot
Copy link

bedevere-bot commented Jan 22, 2022

GH-30783 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit that referenced this pull request Jan 22, 2022
(cherry picked from commit 5a53400)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
asvetlov pushed a commit that referenced this pull request Jan 22, 2022
(cherry picked from commit 5a53400)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
(cherry picked from commit 5a53400)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants