Ich habe Probleme beim Versuch, alle Ergebnisse, die von pytest angezeigt werden, in einer Datei zu speichern (txt, log, egal). Im Test Beispiel unten, würde ich erfassen möchte, was in der Konsole in einen Text/Log-Datei von einer Art angezeigt:Wie pytests Ergebnisse/Protokolle in einer Datei speichern?
import pytest
import os
def test_func1():
assert True
def test_func2():
assert 0 == 1
if __name__ == '__main__':
pytest.main(args=['-sv', os.path.abspath(__file__)])
Console Ausgang würde ich gerne in eine Textdatei speichern:
test-mbp:hi_world ua$ python test_out.py
================================================= test session starts =================================================
platform darwin -- Python 2.7.6 -- py-1.4.28 -- pytest-2.7.1 -- /usr/bin/python
rootdir: /Users/tester/PycharmProjects/hi_world, inifile:
plugins: capturelog
collected 2 items
test_out.py::test_func1 PASSED
test_out.py::test_func2 FAILED
====================================================== FAILURES =======================================================
_____________________________________________________ test_func2 ______________________________________________________
def test_func2():
> assert 0 == 1
E assert 0 == 1
test_out.py:9: AssertionError
========================================= 1 failed, 1 passed in 0.01 seconds ==========================================
test-mbp:hi_world ua$
Letzter Befehl nicht unter Windows funktioniert. –