pytest case design principle study notes (d)

First, the principle of Design Example

  • Filename test _ *. Py files and * _test.py
  • At the beginning of the function test_
  • At the beginning of the test class
  • At the beginning of the method test_
  • All packages package must have a __init__.py file

Two, cmd command line mode of operation

  • pytest
  • py.test
  • python -m pytest

With no arguments, when a folder under execution, it will find use cases that folder all the eligible (see design principles with examples)

Third, rule execution cases

  1. Perform all use cases in a directory

    pytest file name /

  2. The use case under a certain file py

    pytest script name .py

  3. -k chat by Keyword

    pytest -k "Myclass and not method"

It will run a test to a given expression matching name string, wherein the python comprises using a file name, class name and function name as a variable operator. The above example will run TestMyClass.test_something without running TestMyClass.test_method_simple.

  4. Press nodes running

Testing each collected assigned a unique the nodeId, which illustrates the module file name and the class name followed by the desired character from the parameters of the function names and arguments, separated by :: characters.

Run .py module inside a function

    pytest test_mod.py::test_func

Run .py module inside, inside a test class method

    pytest test_mod.py::TestClass::test_method

  The tag expression

    pytest -m smoke

Will run with @ pytest.mark.smoke decorator modified all tests

  6. Run from the bag

    pytest --pyargs pkg.testing

This will import pkg.testing and use its file system location to find and run the test

 

Guess you like

Origin www.cnblogs.com/helloTerry1987/p/10963521.html