|
| 1 | +================ |
| 2 | +pytest-reportlog |
| 3 | +================ |
| 4 | + |
| 5 | +|python| |version| |anaconda| |ci| |black| |
| 6 | + |
| 7 | +.. |version| image:: http://img.shields.io/pypi/v/pytest-reportlog.svg |
| 8 | + :target: https://pypi.python.org/pypi/pytest-reportlog |
| 9 | + |
| 10 | +.. |anaconda| image:: https://img.shields.io/conda/vn/conda-forge/pytest-reportlog.svg |
| 11 | + :target: https://anaconda.org/conda-forge/pytest-reportlog |
| 12 | + |
| 13 | +.. |ci| image:: https://github.com/pytest-dev/pytest-reportlog/workflows/build/badge.svg |
| 14 | + :target: https://github.com/pytest-dev/pytest-reportlog/actions |
| 15 | + |
| 16 | +.. |python| image:: https://img.shields.io/pypi/pyversions/pytest-reportlog.svg |
| 17 | + :target: https://pypi.python.org/pypi/pytest-reportlog/ |
| 18 | + |
| 19 | +.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg |
| 20 | + :target: https://github.com/ambv/black |
| 21 | + |
| 22 | +Replacement for the ``--resultlog`` option, focused in simplicity and extensibility. |
| 23 | + |
| 24 | +.. note:: |
| 25 | + This plugin was created so developers can try out the candidate to replace the |
| 26 | + `deprecated --resultlog <https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log>`__ option. |
| 27 | + |
| 28 | + If you use ``--resultlog``, please try out ``--report-log`` and provide feedback. |
| 29 | + |
| 30 | +Usage |
| 31 | +===== |
| 32 | + |
| 33 | +The ``--report-log=FILE`` option writes *report logs* into a file as the test session executes. |
| 34 | + |
| 35 | +Each line of the report log contains a self contained JSON object corresponding to a testing event, |
| 36 | +such as a collection or a test result report. The file is guaranteed to be flushed after writing |
| 37 | +each line, so systems can read and process events in real-time. |
| 38 | + |
| 39 | +Each JSON object contains a special key ``$report_type``, which contains a unique identifier for |
| 40 | +that kind of report object. For future compatibility, consumers of the file should ignore reports |
| 41 | +they don't recognize, as well as ignore unknown properties/keys in JSON objects that they do know, |
| 42 | +as future pytest versions might enrich the objects with more properties/keys. |
| 43 | + |
| 44 | + |
| 45 | +Example |
| 46 | +------- |
| 47 | + |
| 48 | +Consider this file: |
| 49 | + |
| 50 | +.. code-block:: python |
| 51 | +
|
| 52 | + # content of test_report_example.py |
| 53 | +
|
| 54 | +
|
| 55 | + def test_ok(): |
| 56 | + assert 5 + 5 == 10 |
| 57 | +
|
| 58 | +
|
| 59 | + def test_fail(): |
| 60 | + assert 4 + 4 == 1 |
| 61 | +
|
| 62 | +
|
| 63 | +:: |
| 64 | + |
| 65 | + $ pytest test_report_example.py -q --report-log=log.json |
| 66 | + .F [100%] |
| 67 | + ================================= FAILURES ================================= |
| 68 | + ________________________________ test_fail _________________________________ |
| 69 | + |
| 70 | + def test_fail(): |
| 71 | + > assert 4 + 4 == 1 |
| 72 | + E assert (4 + 4) == 1 |
| 73 | + |
| 74 | + test_report_example.py:8: AssertionError |
| 75 | + ------------------- generated report log file: log.json -------------------- |
| 76 | + 1 failed, 1 passed in 0.12s |
| 77 | + |
| 78 | +The generated ``log.json`` will contain a JSON object per line: |
| 79 | + |
| 80 | +:: |
| 81 | + |
| 82 | + $ cat log.json |
| 83 | + {"pytest_version": "5.2.2", "$report_type": "SessionStart"} |
| 84 | + {"nodeid": "", "outcome": "passed", "longrepr": null, "result": null, "sections": [], "_report_type": "CollectReport"} |
| 85 | + {"nodeid": ".tmp/test_report_example.py", "outcome": "passed", "longrepr": null, "result": null, "sections": [], "_report_type": "CollectReport"} |
| 86 | + {"nodeid": ".tmp/test_report_example.py::test_ok", "location": [".tmp\\test_report_example.py", 0, "test_ok"], "keywords": {"test_ok": 1, "pytest-reportlog": 1, ".tmp/test_report_example.py": 1}, "outcome": "passed", "longrepr": null, "when": "setup", "user_properties": [], "sections": [], "duration": 0.0, "_report_type": "TestReport"} |
| 87 | + {"nodeid": ".tmp/test_report_example.py::test_ok", "location": [".tmp\\test_report_example.py", 0, "test_ok"], "keywords": {"test_ok": 1, "pytest-reportlog": 1, ".tmp/test_report_example.py": 1}, "outcome": "passed", "longrepr": null, "when": "call", "user_properties": [], "sections": [], "duration": 0.0, "_report_type": "TestReport"} |
| 88 | + {"nodeid": ".tmp/test_report_example.py::test_ok", "location": [".tmp\\test_report_example.py", 0, "test_ok"], "keywords": {"test_ok": 1, "pytest-reportlog": 1, ".tmp/test_report_example.py": 1}, "outcome": "passed", "longrepr": null, "when": "teardown", "user_properties": [], "sections": [], "duration": 0.00099945068359375, "_report_type": "TestReport"} |
| 89 | + {"nodeid": ".tmp/test_report_example.py::test_fail", "location": [".tmp\\test_report_example.py", 4, "test_fail"], "keywords": {"test_fail": 1, "pytest-reportlog": 1, ".tmp/test_report_example.py": 1}, "outcome": "passed", "longrepr": null, "when": "setup", "user_properties": [], "sections": [], "duration": 0.0, "_report_type": "TestReport"} |
| 90 | + {"nodeid": ".tmp/test_report_example.py::test_fail", "location": [".tmp\\test_report_example.py", 4, "test_fail"], "keywords": {"test_fail": 1, "pytest-reportlog": 1, ".tmp/test_report_example.py": 1}, "outcome": "failed", "longrepr": {"reprcrash": {"path": "D:\\projects\\pytest-reportlog\\.tmp\\test_report_example.py", "lineno": 6, "message": "assert (4 + 4) == 1"}, "reprtraceback": {"reprentries": [{"type": "ReprEntry", "data": {"lines": [" def test_fail():", "> assert 4 + 4 == 1", "E assert (4 + 4) == 1"], "reprfuncargs": {"args": []}, "reprlocals": null, "reprfileloc": {"path": ".tmp\\test_report_example.py", "lineno": 6, "message": "AssertionError"}, "style": "long"}}], "extraline": null, "style": "long"}, "sections": [], "chain": [[{"reprentries": [{"type": "ReprEntry", "data": {"lines": [" def test_fail():", "> assert 4 + 4 == 1", "E assert (4 + 4) == 1"], "reprfuncargs": {"args": []}, "reprlocals": null, "reprfileloc": {"path": ".tmp\\test_report_example.py", "lineno": 6, "message": "AssertionError"}, "style": "long"}}], "extraline": null, "style": "long"}, {"path": "D:\\projects\\pytest-reportlog\\.tmp\\test_report_example.py", "lineno": 6, "message": "assert (4 + 4) == 1"}, null]]}, "when": "call", "user_properties": [], "sections": [], "duration": 0.0009992122650146484, "_report_type": "TestReport"} |
| 91 | + {"nodeid": ".tmp/test_report_example.py::test_fail", "location": [".tmp\\test_report_example.py", 4, "test_fail"], "keywords": {"test_fail": 1, "pytest-reportlog": 1, ".tmp/test_report_example.py": 1}, "outcome": "passed", "longrepr": null, "when": "teardown", "user_properties": [], "sections": [], "duration": 0.0, "_report_type": "TestReport"} |
| 92 | + {"exitstatus": 1, "$report_type": "SessionFinish"} |
| 93 | + |
| 94 | +License |
| 95 | +======= |
| 96 | + |
| 97 | +Distributed under the terms of the `MIT`_ license. |
| 98 | + |
| 99 | +.. _MIT: https://github.com/pytest-dev/pytest-mock/blob/master/LICENSE |
0 commit comments