Best Python code snippet using pytest
integration.py
Source:integration.py
...113 def test_rerun(self, testdir):114 testdir.makeconftest("""115 from _pytest.runner import runtestprotocol116 def pytest_runtest_protocol(item, nextitem):117 runtestprotocol(item, log=False, nextitem=nextitem)118 runtestprotocol(item, log=True, nextitem=nextitem)119 """)120 testdir.makepyfile("""121 import pytest122 count = 0123 req = None124 @pytest.fixture125 def fix(request):126 global count, req127 assert request != req128 req = request129 print ("fix count %s" % count)130 count += 1131 def test_fix(fix):132 pass...
plugin.py
Source:plugin.py
...49 tr.reload()50 tr.update_test_record_by_object(tc.test_case_id, tc)51def pytest_runtest_protocol(item, nextitem):52 if item.config.getoption('polarion_run') is not None:53 reports = runtestprotocol(item, nextitem=nextitem)54 # get polarion objects55 tr = item.config.getoption('test_run_obj')56 tc = item.config.getoption('test_run_records')[item.get_marker("polarion_id").args[0]]57 for report in reports:58 if report.when == 'call':59 # print '\n%s --- %s --- %s' % (item.name, item.get_marker("polarion_id"), report.outcome)60 # Build up traceback massage61 trace = ''62 if not report.passed:63 trace = '{0}:{1}\n{2}'.format(report.location, report.when, report.longrepr)64 tc.result = report.outcome65 tc.executed = datetime.datetime.now()66 tc.executed_by = tc.logged_in_user_id67 tc.duration = report.duration...
__init__.py
Source:__init__.py
...42 EXITSTATUS_TESTEXIT = 443 import marshal44 def runforked():45 try:46 reports = runtestprotocol(item, log=False)47 except KeyboardInterrupt:48 os._exit(EXITSTATUS_TESTEXIT)49 return marshal.dumps([serialize_report(x) for x in reports])50 ff = py.process.ForkedFunc(runforked)51 result = ff.waitfinish()52 if result.retval is not None:53 report_dumps = marshal.loads(result.retval)54 return [runner.TestReport(**x) for x in report_dumps]55 else:56 if result.exitstatus == EXITSTATUS_TESTEXIT:57 pytest.exit("forked test item %s raised Exit" % (item,))58 return [report_process_crash(item, result)]59def report_process_crash(item, result):60 try:...
testor_thread.py
Source:testor_thread.py
...17 def pytest_sessionstart(self, session):18 print("********************* start *********************")19 #@pytest.hookimpl(hookwrapper=True)20 def pytest_runtest_protocol(self, item, nextitem):21 reports = runtestprotocol(item, nextitem=nextitem)22 for report in reports:23 if report.when == 'call':24 self.results[item.name] = report.outcome25 print('%s --- %s' % (item.name, report.outcome))26 self.runtimeSig.emit(item.name, report.outcome)27 return True28 def pytest_sessionfinish(self, exitstatus): 29 print("********************* finish *********************")30 31 if exitstatus == EXIT_OK:32 print('TEST PASS!!!')33 self.finalResultSig.emit('PASS')34 35 if exitstatus == EXIT_TESTSFAILED:...
Looking for an in-depth tutorial around pytest? LambdaTest covers the detailed pytest tutorial that has everything related to the pytest, from setting up the pytest framework to automation testing. Delve deeper into pytest testing by exploring advanced use cases like parallel testing, pytest fixtures, parameterization, executing multiple test cases from a single file, and more.
Skim our below pytest tutorial playlist to get started with automation testing using the pytest framework.
https://www.youtube.com/playlist?list=PLZMWkkQEwOPlcGgDmHl8KkXKeLF83XlrP
Get 100 minutes of automation test minutes FREE!!