One, HTML report error
This introduction pytest third-party plug-ins pytest-html
Here does not introduce how to use, because how to use the Internet has a lot of, here to give you a reference to the address, pytest-html generated HTML report
Here's how the pytest generated report is presented here today, which is useful in Web automation testing.
The requirement is a test case error, as follows:
We want to create a new plugin file about the conftest.py, note that the file name can not be changed, because pytest-html will automatically find this self-written plugin, the content is as follows:
fromSeleniumImportWebdriverImportPytestdriver=None@pytest.mark.hookwrapperdefPytest_runtest_makereport (item):"""Extends the Pytest Plugin to take and embed screenshot in HTML report, whenever test fails. :p Aram Item:"""pytest_html= Item.config.pluginmanager.getplugin ('HTML') Outcome=yield Report=Outcome.get_result () extra= GetAttr (Report,'Extra', []) ifReport.when = ='Pager' orReport.when = ="Setup": Xfail= hasattr (Report,'Wasxfail') if(report.skipped andXfail)or(report.failed and notxfail): file_name= Report.nodeid.replace ("::","_")+". PNG"_capture_screenshot (file_name)iffile_name:html='<div>' 'onclick= "window.open (THIS.SRC)" align= "right"/></div>'%file_name extra.append (pytest_html.extras.html (HTML)) Report.extra=Extradef_capture_screenshot (name): Driver.get_screenshot_as_file (name) @pytest. Fixture (Scope='Session', autouse=True)defbrowser ():GlobalDriverifDriver isNone:driver=Webdriver. Firefox ()returnDriver
For information on how the conftest.py file is applied, you can view the document: conftest.py how to put
Next, is to write the use case, in the current folder with Conftest write use case file test_aa.py, as follows
def test_screenshot_on_test_failure (browser): browser.get ("https://www.baidu.com " ) assert False
Then run again with Pytest, running as follows:
E:\>pytest-s-V test_aa.py--html=report.html
Then we can see the PNG file with the name of the report.html file and the test case under the E disk
Open the HTML file with the following details:
Reference:
Https://pypi.python.org/pypi/pytest-html
Second, failed retry
The plugin used is pytest-rerunfailures, the official website here
How to use:
Adding the--rerun parameter when testing
Py.test--rerun 2 use case failed and re-tested 2 times
Python pytest test Framework Introduction to the four-----pytest-html plug-in HTML with error and failure re-testing mechanism