pytest学习(3)

在pytest 2.0以上的版本里,我们也可以通过python -m pytest ...来调用。这实际上和pytest 。。。几乎一摸一样。

只是用python的时候,把当面目录也加入到sys.path中。

pytest的返回值如下:

Exit code 0:	All tests were collected and passed successfully
Exit code 1:	Tests were collected and run but some of the tests failed
Exit code 2:	Test execution was interrupted by the user
Exit code 3:	Internal error happened while executing tests
Exit code 4:	pytest command line usage error
Exit code 5:	No tests were collected

 

pytest的一些常用的命令你:

pytest --version 显示pytest import的版本,以及已经注册的插件。

C:fitmehttpie	ests>pytest --version
This is pytest version 3.1.3, imported from c:python35libsite-packagespytest.py
setuptools registered plugins:
  pytest-httpbin-0.2.3 at c:python35libsite-packagespytest_httpbinplugin.py

  pytest 碰到第几个错误停止:

pytest -x            # stop after first failure
pytest --maxfail=2    # stop after two failures

  指定路径啊,文件啊,文件里的函数,类等进行测试。

pytest test_mod.py   # run tests in module
pytest somepath      # run all tests below somepath
pytest -k stringexpr # only run tests with names that match the
                      # "string expression", e.g. "MyClass and not method"
                      # will select TestMyClass.test_something
                      # but not TestMyClass.test_method_simple
pytest 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
pytest test_mod.py::TestClass::test_method  # run a single method in
                                             # a single class

  

原文地址:https://www.cnblogs.com/aomi/p/7216186.html