-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add Sphinx-compatible docstrings and inline comments for main.py (lines 245-490) #13091
base: main
Are you sure you want to change the base?
Add Sphinx-compatible docstrings and inline comments for main.py (lines 245-490) #13091
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mohammadaminjohari for PR, just 2 suggestions for reference:
-
Keep the style of the docstring consistent with the existing pytest code, for example,
-
Do not modify the inline comments for now, it is not necessary at first glance
@@ -248,24 +248,37 @@ def pytest_addoption(parser: Parser) -> None: | |||
|
|||
|
|||
def validate_basetemp(path: str) -> str: | |||
# GH 7119 | |||
""" | |||
Validate the base temporary directory path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GH 7119
refers to #7119 clarifying the origin of the code, suggest keeping it in the docstrings, for example:
Validate the base temporary directory path (see also :issue:`7119`).
@@ -275,17 +288,26 @@ def is_ancestor(base: Path, query: Path) -> bool: | |||
def wrap_session( | |||
config: Config, doit: Callable[[Config, Session], int | ExitCode | None] | |||
) -> int | ExitCode: | |||
"""Skeleton command line program.""" | |||
""" | |||
Execute the pytest session within a controlled wrapper. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose is to execute doit, not to execute session,
Consider modifying to:
Execute a function within a pytest session.
initstate = 2 | ||
session.exitstatus = doit(config, session) or 0 | ||
session.exitstatus = doit(config, session) or 0 # Execute main logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now,execute doit
, not execute main
. (These line comments may be unnecessary because the method names are already intuitive enough)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks you for opening the PR. I started a review but @dongfangtianyu did something more detailled, i'll just leave what I had. About inline comment in particular : Commentting what the code does is duplicating informations, inline comment should be about why the code is done this way not what it does.
argparse.ArgumentTypeError: If the path is invalid, such as being empty, the | ||
current working directory, or a parent directory of the current working directory. | ||
""" | ||
# Error message for invalid paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Error message for invalid paths |
excinfo = None # type: ignore | ||
os.chdir(session.startpath) | ||
os.chdir(session.startpath) # Return to the initial directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.chdir(session.startpath) # Return to the initial directory | |
os.chdir(session.startpath) |
initstate = 2 | ||
session.exitstatus = doit(config, session) or 0 | ||
session.exitstatus = doit(config, session) or 0 # Execute main logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
session.exitstatus = doit(config, session) or 0 # Execute main logic | |
session.exitstatus = doit(config, session) or 0 |
initstate = 1 | ||
config.hook.pytest_sessionstart(session=session) | ||
config.hook.pytest_sessionstart(session=session) # Notify start of session |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config.hook.pytest_sessionstart(session=session) # Notify start of session | |
config.hook.pytest_sessionstart(session=session) |
session = Session.from_config(config) | ||
session.exitstatus = ExitCode.OK | ||
initstate = 0 | ||
try: | ||
try: | ||
config._do_configure() | ||
config._do_configure() # Initialize pytest configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config._do_configure() # Initialize pytest configuration | |
config._do_configure() |
msg = "basetemp must not be empty, the current working directory or any parent directory of it" | ||
|
||
# empty path | ||
# Check for an empty path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Check for an empty path |
Hi @mohammadaminjohari , |
This pull request addresses issue #12979 by enhancing the documentation and readability of the file pytest/src/_pytest/main.py in the range of lines 245 to 490.
Changes Made:
Functions and Classes Updated:
Best regards,
Mohammadamin Johari