8000 Direct invocation of `test_inspect/test_inspect.py` fails · Issue #116785 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Direct invocation of test_inspect/test_inspect.py fails #116785

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

Closed
sobolevn opened this issue Mar 14, 2024 · 8 comments
Closed

Direct invocation of test_inspect/test_inspect.py fails #116785

sobolevn opened this issue Mar 14, 2024 · 8 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member
sobolevn commented Mar 14, 2024

Bug report

» ./python.exe Lib/test/test_inspect/test_inspect.py
/Users/sobolev/Desktop/cpython2/Lib/test/test_inspect/test_inspect.py:43: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import inspect_fodder as mod
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/Lib/test/test_inspect/test_inspect.py", line 43, in <module>
    from . import inspect_fodder as mod
ImportError: attempted relative import with no known parent package                                                         

I will send a PR.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Mar 14, 2024
@sobolevn sobolevn self-assigned this Mar 14, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Mar 14, 2024
@vstinner
Copy link
Member

Should we really encourage usage of running directly tests?

Maybe it's time to give up on if __name__ == '__main__': ... and promote the new unittest CLI instead:

./python -m unittest Lib/test/test_inspect/test_inspect.py

But well, I'm fine with the fix.

cc @serhiy-storchaka

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 14, 2024
…6787)

(cherry picked from commit 66fb613)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 14, 2024
…6787)

(cherry picked from commit 66fb613)

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

I find this really useful when you can click on a file in IDE and say "run this file". No build step, no settings, no nothing. It just works (until it does not 😄 ).

sobolevn added a commit that referenced this issue Mar 14, 2024
…#116794)

gh-116785: Fix direct invocation of `test_inspect` (GH-116787)
(cherry picked from commit 66fb613)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit that referenced this issue Mar 14, 2024
…#116795)

gh-116785: Fix direct invocation of `test_inspect` (GH-116787)
(cherry picked from commit 66fb613)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@serhiy-storchaka
Copy link
Member

It was useful to make every toplevel test be runnable as a script. But it never worked well for tests in subdirectories and required too many inconvenient changes, so I gave up on this.

@vstinner
Copy link
Member

I always run "./python -m test <test_name>". The only time when I really have to run a test manually if when everything goes wrong and I need a fully control on what's going on. Like when I'm debugging regrtest or unittest.

@vstinner
Copy link
Member

I close the issue, it's now fixed :-)

@serhiy-storchaka
Copy link
Member

Yes, it is what I usually do too. Running test directly is only useful to test some unexpected dependencies on libregrtest. It was more relevant in the past, when libregrtest used non-standard way to collect tests (test_main and explicit list of test classes), so some tests could be omitted.

@terryjreedy
Copy link
Member

I routinely run tests I am editing from the editor. Of course, idlelib tests have worked that way from the beginning because I developed or tested them that way from the beginning.

@vstinner
Copy link
Member

Ok, it's good to see how people are running tests. Apparently, the trend is to continue allowing to run them directly. So let's do that 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants
0