pytest —help可查看pytest.ini的设置选项

  1. [pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg file found:
  2. markers (linelist): markers for test functions
  3. empty_parameter_set_mark (string):
  4. default marker for empty parametersets
  5. norecursedirs (args): directory patterns to avoid for recursion
  6. testpaths (args): directories to search for tests when no files or directories are given in the command line.
  7. usefixtures (args): list of default fixtures to be used with this project
  8. python_files (args): glob-style file patterns for Python test module discovery
  9. python_classes (args):
  10. prefixes or glob names for Python test class discovery
  11. python_functions (args):
  12. prefixes or glob names for Python test function and method discovery
  13. disable_test_id_escaping_and_forfeit_all_rights_to_community_support (bool):
  14. disable string escape non-ascii characters, might cause unwanted side effects(use at your own risk)
  15. console_output_style (string):
  16. console output: "classic", or with additional progress information ("progress" (percentage) | "count").
  17. xfail_strict (bool): default for the strict parameter of xfail markers when not given explicitly (default: False)
  18. enable_assertion_pass_hook (bool):
  19. Enables the pytest_assertion_pass hook.Make sure to delete any previously generated pyc cache files.
  20. junit_suite_name (string):
  21. Test suite name for JUnit report
  22. junit_logging (string):
  23. Write captured log messages to JUnit report: one of no|log|system-out|system-err|out-err|all
  24. junit_log_passing_tests (bool):
  25. Capture log information for passing tests to JUnit report:
  26. junit_duration_report (string):
  27. Duration time to report: one of total|call
  28. junit_family (string):
  29. Emit XML for schema: one of legacy|xunit1|xunit2
  30. doctest_optionflags (args):
  31. option flags for doctests
  32. doctest_encoding (string):
  33. encoding used for doctest files
  34. cache_dir (string): cache directory path.
  35. filterwarnings (linelist):
  36. Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.
  37. log_print (bool): default value for --no-print-logs
  38. log_level (string): default value for --log-level
  39. log_format (string): default value for --log-format
  40. log_date_format (string):
  41. default value for --log-date-format
  42. log_cli (bool): enable log display during test run (also known as "live logging").
  43. log_cli_level (string):
  44. default value for --log-cli-level
  45. log_cli_format (string):
  46. default value for --log-cli-format
  47. log_cli_date_format (string):
  48. default value for --log-cli-date-format
  49. log_file (string): default value for --log-file
  50. log_file_level (string):
  51. default value for --log-file-level
  52. log_file_format (string):
  53. default value for --log-file-format
  54. log_file_date_format (string):
  55. default value for --log-file-date-format
  56. log_auto_indent (string):
  57. default value for --log-auto-indent
  58. faulthandler_timeout (string):
  59. Dump the traceback of all threads if a test takes more than TIMEOUT seconds to finish. Not available on Windows.
  60. addopts (args): extra command line options
  61. minversion (string): minimally required pytest version
  62. render_collapsed (bool):
  63. Open the report with all rows collapsed. Useful for very large reports

常见的pytest.ini配置项

markers:为用例打标记,详见mark实现根据标签执行用例
addopts:可修改默认命令行选项,假设我们每次执行用例都需要执行一大串指令,可把执行指令添加到pytest.ini,

  1. # pytest.ini
  2. [pytest]
  3. # #--self-contained-html 为了防止分享报告的时候样式丢失
  4. addopts = -v --rerun 1 --html=./report/report.html --self-contained-html

设置如上之后,打开cmd只需要输入pytest就能默认带上这些默认参数