FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-46425: fix direct invocation of `asyncio` tests by sobolevn · Pull Request #30725 · python/cpython · GitHub

Repository navigation

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

Merged
asvetlov merged 1 commit into
python:mainfrom
sobolevn:issue-46425-asyncio
Jan 22, 2022
Merged

asvetlov merged 1 commit into
python:mainfrom
sobolevn:issue-46425-asyncio

Conversation

sobolevn commented Jan 20, 2022 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

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

kumaraditya303 left a comment •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there a reason that you run tests like scripts?

Copy link
Copy Markdown
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.

asvetlov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

@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>

Copy link
Copy Markdown

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>

Copy link
Copy Markdown

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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL