项目作者: rvprasad

项目描述 :
A pytest plugin to treat non-assertion failures as test errors.
高级语言: Python
项目地址: git://github.com/rvprasad/pytest-finer-verdicts.git
创建时间: 2016-05-30T17:16:01Z
项目社区:https://github.com/rvprasad/pytest-finer-verdicts

开源协议:BSD 3-Clause "New" or "Revised" License

下载


pytest-finer-verdicts

A pytest plugin to treat non-assertion failures as test errors.

Getting the plugin

The plugin can be installed via pip install pytest-finer-verdicts. Similarly, it can be uninstalled via pip uninstall pytest-finer-verdicts.

Usage

Consider the following snippet in a file test.py (available as temp/test.py in the repository).

  1. import pytest
  2. def test_pass():
  3. assert 70 <= 75
  4. def test_fail():
  5. assert 75 <= 70
  6. def test_error():
  7. raise RuntimeError()
  8. def test_pytest_fail():
  9. pytest.fail("Fail")
  10. def test_pytest_raises():
  11. with pytest.raises(ValueError):
  12. raise IndexError()

With pytest-finer-verdicts plugin, py.test test.py -v will produce the following output.

  1. collected 5 items
  2. test.py::test_pass PASSED
  3. test.py::test_fail FAILED
  4. test.py::test_error ERROR
  5. test.py::test_pytest_fail FAILED
  6. test.py::test_pytest_raises ERROR
  7. ================================== ERRORS ===================================
  8. _______________________ ERROR at setup of test_error ________________________
  9. def test_error():
  10. > raise RuntimeError()
  11. E RuntimeError
  12. test.py:13: RuntimeError
  13. ___________________ ERROR at setup of test_pytest_raises ____________________
  14. def test_pytest_raises():
  15. with pytest.raises(ValueError):
  16. > raise IndexError()
  17. E IndexError
  18. test.py:22: IndexError
  19. ================================= FAILURES ==================================
  20. _________________________________ test_fail _________________________________
  21. def test_fail():
  22. > assert 75 <= 70
  23. E assert 75 <= 70
  24. test.py:9: AssertionError
  25. _____________________________ test_pytest_fail ______________________________
  26. def test_pytest_fail():
  27. > pytest.fail("Fail")
  28. E Failed: Fail
  29. test.py:17: Failed
  30. ================ 2 failed, 1 passed, 2 error in 0.05 seconds ================

Notice how test_error and test_pytest_raises are flagged as test errors by the plugin.

Attribution

Copyright (c) 2016-2018, Venkatesh-Prasad Ranganath

Licensed under BSD 3-clause “New” or “Revised” License (https://choosealicense.com/licenses/bsd-3-clause/)

Authors: Venkatesh-Prasad Ranganath