Skip to content

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

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

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

Choose a reason for hiding this comment

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

Is there a reason that you run tests like scripts?

@sobolevn
Copy link
Member Author

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

Choose a reason for hiding this comment

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

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

@asvetlov asvetlov added needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels Jan 22, 2022
@asvetlov asvetlov merged commit 5a53400 into python:main Jan 22, 2022
@miss-islington
Copy link
Contributor

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

@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 <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Jan 22, 2022
@bedevere-bot
Copy link

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 <[email protected]>
@bedevere-bot
Copy link

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

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Jan 22, 2022
miss-islington added a commit that referenced this pull request Jan 22, 2022
(cherry picked from commit 5a53400)

Co-authored-by: Nikita Sobolev <[email protected]>
asvetlov pushed a commit that referenced this pull request Jan 22, 2022
(cherry picked from commit 5a53400)

Co-authored-by: Nikita Sobolev <[email protected]>

Co-authored-by: Nikita Sobolev <[email protected]>
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 <[email protected]>
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.

7 participants