Pytest prepared by Example 1

 
First, write pytest test sample is very simple, just follow these rules:
  • Test file begins test_ (ending _test can)
  • Test classes to begin the test, and not with __init__ method
  • Test function to begin with test_
  • Assertions to assert basic
 
 
 
Second, the method of performing a wide variety of test samples, the first instance is executed directly py.test, above, the second example is a test file to transfer py.test. In fact, there are many ways to perform py.test test
py.test # run all tests below current dir
py.test test_mod.py # run tests in module
py.test somepath # run all tests below somepath
py.test -k stringexpr # only run tests with names that match the
# the "string expression", e.g. "MyClass and not method"
# will select TestMyClass.test_something
# but not TestMyClass.test_method_simple
py.test test_mod.py::test_func # only run tests that match the "node ID",
# e.g "test_mod.py::test_func" will select
# only test_func in test_mod.py
 
Third, generate test reports
Generate reports in HTML format:
py.test --resultlog=path
Generate reports in XML format:
py.test --junitxml=path

Guess you like

Origin www.cnblogs.com/TomBombadil/p/10977852.html