当前位置:网站首页>Pytest configuration file

Pytest configuration file

2022-06-26 10:18:00 Xiaojing, who likes dumplings

pytest Profile profile

pytest.ini yes pytest Primary profile for , You can change pytest Default behavior of

How to configure pytest

Change the default command line options

For some common command line parameters , such as -v,-s, Regular use , But I don't want to repeat the input , Can be in pytest.ini Of documents addopts To set up

[pytest]
addopts=-v -s
Sign up for spelling mistakes

We can customize tags to manage test cases , For example, the smoke test case is marked as @pytest.mark.smoke, You can register tags in the configuration file to avoid spelling mistakes , The unregistered tag will prompt warning
makers The format is line list

[pytest]
addopts=-v -s
markers=
smoke
regession
Appoint pytest The minimum version of

minversion=3.0

Appoint pytest Ignore some directories

norecurse

Specify test directory

Use testpaths Appoint pytest Which directory to access
Only in pytest When no file directory parameter or test case identifier is specified , This option is enabled

Change test search rules

pytest Standard test search rules :

  1. Start with one or more directories , You can specify a file name or directory name on the command line , If not specified , Use the current directory
  2. Recursively query the test modules under this directory and all subdirectories
  3. The test module is named test_.py or _test.py The file of
  4. Find in the test module to test_ Function name at the beginning
  5. Find a name to Test Initial class , among , First, filter out the contents __init__ Class of function , Find the class with test_ Class side at the beginning

You can change the search rules in the configuration file
python_classes Change the search rules for the class
python_classes=Test TestSuite
python_files Change the default search rules for files
python_files=test_
test check
python_functions Change the rules for testing functions and methods
python_functions=test_* check_*

[pytest]
addopts=-v -s
markers=
       smoke
       regession
python_classes=Test* Suite*
python_files=test_* *_test check_*
python_functions=test_* check_*
To configure log

log_file=…/log/log.txt
log_file_level=INFO
log_file_format= %(asctime)s %(levelname)s %(message)s
log_date_format = %Y-%m-%d %H:%M:%S
log_file Is to output the log to a file
log_cli_level
log_cli_format
log_cli_date_format
Output the log to the console

[pytest]
addopts=-v -s
markers=
        smoke
        regession
python_classes=Test* Suite*
python_files=test_* *_test check_*
python_functions=test_* check_*
log_file=../log/log.txt
log_file_level=INFO
log_file_format= %(asctime)s %(levelname)s %(message)s
log_date_format = %Y-%m-%d %H:%M:%S

Source code :

def my_add(x,y):
    print("test2")
    Log.info("test2")
    return x+y

Test code :

def test_add_threee():
    result=my_add(3,4)
    assert result==7

Please refer to the official website for details :link.

原网站

版权声明
本文为[Xiaojing, who likes dumplings]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170544485578.html