pytest_notes
This is an old revision of the document!
test a script that prints to stdout
tags | test case for print
snippet 1:
def test_foo(capsys): ... captured = capsys.readouterr() ... assert captured.out == expected_output
snippet 2:
out, error = capsys.readouterr()
Ref:-
- See https://docs.pytest.org/en/stable/capture.html#accessing-captured-output-from-a-test-function for help on how capsys works in pytest.
- https://stackoverflow.com/a/56300627/6305733 - contains a simple example; I first came across capsys here.
- my usages:
- https://github.com/KamarajuKusumanchi/rutils/blob/master/python3/tests/lib/test_DataFrameUtils.py - tests dataframe printed to stdout
- https://github.com/KamarajuKusumanchi/rutils/blob/master/python3/tests/test_get_column_names.py - I used capsys for the first time here
run pytest on the current file from the current file
tags | run pytest from main function, pytest run parameterized test
pytest_notes.1675264005.txt.gz · Last modified: 2023/02/01 15:06 by raju