Skip to content

doc: Adding exit code for pytest usage examples (#8790) #8800

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 3 commits into from
Jun 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions doc/en/how-to/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ You can invoke ``pytest`` from Python code directly:

.. code-block:: python

pytest.main()
retcode = pytest.main()

this acts as if you would call "pytest" from the command line.
It will not raise ``SystemExit`` but return the exitcode instead.
It will not raise :class:`SystemExit` but return the :ref:`exit code <exit-codes>` instead.
You can pass in options and arguments:

.. code-block:: python

pytest.main(["-x", "mytestdir"])
retcode = pytest.main(["-x", "mytestdir"])

You can specify additional plugins to ``pytest.main``:

Expand All @@ -191,7 +191,8 @@ You can specify additional plugins to ``pytest.main``:
print("*** test run reporting finishing")


pytest.main(["-qq"], plugins=[MyPlugin()])
if __name__ == "__main__":
Copy link
Member

Choose a reason for hiding this comment

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

👍

sys.exit(pytest.main(["-qq"], plugins=[MyPlugin()]))

Running it will show that ``MyPlugin`` was added and its
hook was invoked:
Expand Down