SLesslyTall
SLesslyTall

Reputation: 261

Get pytest traceback for non-test modules

The traceback provided by pytest is great and super useful for debugging.

Is there a way to run a script using the pytest api even if the script itself does not contain any test modules? Essentially, I would like a way to pinpoint and run a certain function in a script as if it were a test, but get the pytest-formatted traceback.

Upvotes: 2

Views: 74

Answers (1)

Xukrao
Xukrao

Reputation: 8634

The pytest documentation on test discovery states that normally only functions whose name begins with test_ are run. This behaviour can be changed however with the python_functions configuration option. Try entering in the command line:

pytest [script.py] -o python_functions=[script_function]

in which you should replace [script.py] with your python script file path and replace [script_function] with the name of the function that you want to be run.

Upvotes: 3

Related Questions