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

Tries to import __main__.py #229

Closed
flying-sheep opened this issue Nov 2, 2023 · 4 comments · Fixed by #232
Closed

Tries to import __main__.py #229

flying-sheep opened this issue Nov 2, 2023 · 4 comments · Fixed by #232
Labels

Comments

@flying-sheep
Copy link
Contributor

__main__.py doesn’t need a if __name__ == '__main__', since it just exists to be a CLI

Therefore doctestplus shouldn‘t try to import it.

@pllim pllim added the bug label Nov 2, 2023
@pllim
Copy link
Contributor

pllim commented Nov 2, 2023

I don't think we can guess what is CLI and what isn't. You can skip a file if you want to.

https://github.com/scientific-python/pytest-doctestplus#skipping-tests

@flying-sheep
Copy link
Contributor Author

flying-sheep commented Nov 3, 2023

You misunderstand; __main__.py is a standard for defining CLIs in Python.

The content of __main__.py typically isn’t fenced with an if __name__ == '__main__' block. Instead, those files are kept short and import functions to execute from other modules.

There’s no guesswork involved here. Files called __main__.py should not be executed unless you want to run a CLI.

@pllim
Copy link
Contributor

pllim commented Nov 3, 2023

Ah, okay. For some reason, I never encountered this usage myself. Usually it is via entry points. Thanks for the clarification!

@flying-sheep
Copy link
Contributor Author

Some ubiquitous tools like build or pip encourage usage with python -m pkgname as opposed to their pyproject-build/pip entrypoints.

That results in pkgname/__main__.py being executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants