Best Python code snippet using pytest
spydist.py
Source:spydist.py
...72 def pytest_collection_modifyitems(self, session, config, items):73 debug("master:", session, config, items)74 self.service.set_items(items)75 @pytest.mark.trylast76 def pytest_sessionstart(self, session):77 debug("master: pytest_sessionstart", session)78 self.server = rpyc.utils.server.ThreadedServer(self.service)79 self.port = self.server.port80 filename = os.path.join(self.logs_path, "batch.server")81 utils.write_file(filename, str(self.server.port))82 self.thread = threading.Thread(target=self.server.start)83 self.thread.start()84 def pytest_sessionfinish(self, session):85 debug("master: pytest_sessionfinish", session)86 def pytest_runtestloop(self):87 if wa.start_slaves_from_master:88 slaves_init(self.logs_path)89 try:90 conn = rpyc.connect("127.0.0.1", self.port)91 while 1:92 if not getattr(conn.root, "has_pending")():93 break94 debug("master: pytest_runtestloop")95 time.sleep(5)96 except KeyboardInterrupt:97 trace("master: interrupted")98 getattr(conn.root, "shutdown")()99 time.sleep(5)100 os._exit(0)101 def pytest_terminal_summary(self, terminalreporter):102 debug("master: pytest_terminal_summary", terminalreporter)103class BatchSlave(object):104 def __init__(self, config, logs_path):105 self.config = config106 self.items = []107 self.logs_path = logs_path108 @pytest.mark.trylast109 def pytest_sessionstart(self, session):110 debug("slave: pytest_sessionstart", session)111 def pytest_sessionfinish(self, session):112 debug("slave: pytest_sessionfinish", session)113 @pytest.hookimpl(trylast=True)114 def pytest_collection_modifyitems(self, session, config, items):115 debug("slave: pytest_collection_modifyitems", session, config, items)116 self.items = items117 def pytest_runtestloop(self):118 def search_nodeid(entries, nodeid):119 for ent in entries:120 if nodeid == ent.nodeid:121 return ent122 return None123 def finish_test(item):...
spec_pytest_da.py
Source:spec_pytest_da.py
...36 assert callable(da.check.pytest_da.pytest_addoption)37# =============================================================================38class SpecifyPytestSessionstart:39 """40 Specify the da.check.pytest_da.pytest_sessionstart() function.41 """42 # -------------------------------------------------------------------------43 def it_is_callable(self):44 """45 The pytest_sessionstart() function is callable.46 """47 import da.check.pytest_da48 assert callable(da.check.pytest_da.pytest_sessionstart)49# =============================================================================50class SpecifyPytestRuntestSetup:51 """52 Specify the da.check.pytest_da.pytest_runtest_setup() function.53 """54 # -------------------------------------------------------------------------55 def it_is_callable(self):56 """57 The pytest_runtest_setup() function is callable.58 """59 import da.check.pytest_da...
test_main.py
Source:test_main.py
...14 returncode, exc = ret_exc15 c1 = testdir.makeconftest(16 """17 import pytest18 def pytest_sessionstart():19 raise {exc}("boom")20 def pytest_internalerror(excrepr, excinfo):21 returncode = {returncode!r}22 if returncode is not False:23 pytest.exit("exiting after %s..." % excinfo.typename, returncode={returncode!r})24 """.format(25 returncode=returncode, exc=exc.__name__26 )27 )28 result = testdir.runpytest()29 if returncode:30 assert result.ret == returncode31 else:32 assert result.ret == ExitCode.INTERNAL_ERROR...
report_base.py
Source:report_base.py
...50 else:51 self.append_failure(report)52 elif report.skipped:53 self.append_skipped(report)54 def pytest_sessionstart(self):55 demo_util.pause_show_info("pytest_sessionstart in {0}".format(self))...
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!!