Skip to content

Commit 6573107

Browse files
Sripnicoddemussripradha-karkala-nutanix
authored
doc: Adding exit code for pytest usage examples (#8790) (#8800)
* doc: Adding exit code for pytest usage examples (#8790) Fix #8790 Co-authored-by: Bruno Oliveira <[email protected]> Co-authored-by: Sripradha Karkala <[email protected]>
1 parent ef395e1 commit 6573107

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

doc/en/how-to/usage.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ You can invoke ``pytest`` from Python code directly:
168168

169169
.. code-block:: python
170170
171-
pytest.main()
171+
retcode = pytest.main()
172172
173173
this acts as if you would call "pytest" from the command line.
174-
It will not raise ``SystemExit`` but return the exitcode instead.
174+
It will not raise :class:`SystemExit` but return the :ref:`exit code <exit-codes>` instead.
175175
You can pass in options and arguments:
176176

177177
.. code-block:: python
178178
179-
pytest.main(["-x", "mytestdir"])
179+
retcode = pytest.main(["-x", "mytestdir"])
180180
181181
You can specify additional plugins to ``pytest.main``:
182182

@@ -191,7 +191,8 @@ You can specify additional plugins to ``pytest.main``:
191191
print("*** test run reporting finishing")
192192
193193
194-
pytest.main(["-qq"], plugins=[MyPlugin()])
194+
if __name__ == "__main__":
195+
sys.exit(pytest.main(["-qq"], plugins=[MyPlugin()]))
195196
196197
Running it will show that ``MyPlugin`` was added and its
197198
hook was invoked:

0 commit comments

Comments
 (0)