1. Execute on the console
Open cmd and enter the project directory
-
Specify to execute a module pytest testcases\Logistics\Platform\CarSource\test_CarSourceList.py
-
Specify to execute all test files in a directory and its subdirectories pytest testcases\Logistics\Platform\CarSource
-
Specify to execute a test case of a class of a module pytest testcases\Logistics\Platform\Home_page\test_navigation.py::TestNavigation::test_08_navigation
For more usage, refer to using parameters
2. Execute through pytest code
Execute RunTestCase.py directly [automatically find files starting with test_ or py files ending with _test in the current directory]
法一:args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME]
pytest.main(args) [Multiple parameters in [] are separated by 'comma,']
法二:args="pytest -m Navigation"
os.system(args)
-
Specify to execute a certain directory/a certain module/a certain class/a certain use case, use :: connection args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME ,'-v','testcases\Logistics\Platform\CarSource\\test_CarrierShop.py::TestCarrierShop::test_01_carrierShop']
-
Specify to execute multiple directories/multiple modules/multiple classes args = ['--reruns', '1', '--html=./Report/Report.html','-v', 'testcases\Logistics\ Platform\CarSource', 'testcases\Logistics\Platform\Login', r'testcases\Logistics\Platform\Home_page\test_navigation.py']
-
Specify keyword match to run test case name substring (-k ) args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME,'-k',' 01','testcases\Logistics\Platform\CarSource']
-
Specify to execute a label (only one label can be specified at a time) args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME,'-m','CarrierShopTest' ]
-
Execution returns failed args = ['--reruns', '1', '--html=./Report/Report.html', '-v', '--lf']
3. Description of common parameters pytest
-v: Description: It can output more detailed execution information of the use case, such as the file where the use case is located and the name of the use case, etc.
-S: Description: Enter the debugging information in our use case, such as the printing information of print, etc.
-m : Description: Execute a specific test case, "mark"
-k: Description: Execute use cases that contain "keywords", "keywords"
-q: Description: Simplify the output of the console
--lf : When a use case is executed, if there is a failed test case, then we can use this command to rerun the failed test case
--ff : If there is a failed test case in the last test case, when --ff is used, the failed test case will be executed first, and the remaining test cases will be executed again
Friends who are studying for the test can click the small card below