In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to execute Pytest test cases". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to execute Pytest test cases.
Overview of pytest
Pytest is a very mature full-function Python testing framework, the main features are as follows:
1. Simple and flexible, easy to use, rich in documents
2. Support parameterization and fine-grained control of the test cases to be tested
3. It can support simple unit testing and complex functional testing, and can also be used to do automated tests such as selenium/appnium and interface automation testing (pytest+requests).
4. Pytest has many third-party plug-ins and custom extensions, such as pytest-selenium (integrated selenium), pytest-html (perfect html test report generation), pytest-rerunfailures (failed case repeat execution), pytest-xdist (multi-CPU distribution) and so on.
5. Skip and xfail processing of test cases
6. Can be well combined with CI tools, such as jenkins
1. Main function mode
(1) run all pytest.main ()
(2) specify the module pytest.main ('[- vs],','. / testcase/test_day1.py')
(3) specify the directory pytest.main ('[- vs]'),'. / testcase')
(4) specify use case operation through nodeid: nodeid consists of module name, delimiter, class name, method name, and function name.
# pytest.main (["- vs"],'. / interface_testcase/test_day3.py::test_demo11')
# pytest.main (["- vs"],'. / interface_testcase/test_day3.py::TestLogin::test_01_qianghong1')
2. Command line mode
(1) run all: pytest
(2) specify module pytest-vs. / testcase/test_day1.py
(3) specify the directory pytest-vs. / testcase
(4) specify use case operation through nodeid: nodeid consists of module name, delimiter, class name, method name, and function name.
Pytest-vs. / interface_testcase/test_day3.py::test_demo11
Pytest-vs. / interface_testcase/test_day3.py::TestLogin::test_01_qianghong1
Detailed description of parameters:
-s: indicates the output debugging information, including the information printed by print
-v displays more detailed information
-vs is used together
-n supports multithreading or distributed running test cases
# such as # pytest.main (['- vs','./testcase/test_day1.py','-n=2'])
# pytest-vs. / testcase/test_day1.py-n 2
# reruns==number means a failed use case rerun
# pytest-vs. / testcase/test_day2.py-- reruns 2
# pytest.main (['- vs','./testcase/test_day2.py','reruns=2']) # the failed use case reruns twice
#-x means that as long as a use case reports an error, the test stops running
#-maxfail=2 has two failed use cases to stop
#-k specifies the test case pytest-vs test_day2-k "yang" based on part of the test case string
3. Run by reading pytest ini configuration file (the most important way to use it)
# pytest.ini is the core configuration file in the pytest unit test framework
(1) location: usually placed in the root directory of the project
(2) Encoding: it must be ANSI. You can use notepad++ to modify the encoding format.
(3) function: change the default behavior of pytest
(4) running rules: no matter the mode of the main function runs in the command line mode, the configuration file will be read in the area.
[pytest] addopts=-vs # Command Line argument separates the path of the testpaths=./testcase # test case with a space. / testcase/test_day2.py # python_files=test_*.py # Rule python_classes=Test* # Class name Rule python_functions=test # method name
# in the actual project configuration, delete comments as far as possible to ensure unnecessary problems
Thank you for your reading, the above is the content of "how to execute Pytest test cases". After the study of this article, I believe you have a deeper understanding of how to execute Pytest test cases, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.