How to get console out put in pytest
import unittest import pytest class MyTestCase(unittest.TestCase): @pytest.fixture(autouse=True) def capfd(self, capfd): self.capfd = capfd def test_list_not_well_format(self): print("Hello World") out, err = self.capfd.readouterr() print(f"out: {out}\nerr: {err}") self.assertTrue("Hello World" in out)
PYTEST COMMAND:
pytest test.py -o junit_family=xunit2 - junitxml=test-reports/junit.xml
REF: https://docs.pytest.org/en/stable/capture.html#accessing-captured-output-from-a-test-function













