Best Python code snippet using pytest
io_block.py
Source:io_block.py
...12 def __init__(self):13 self._capture: Optional[IOManager] = None14 def start_capturing(self) -> None:15 assert self._capture is None16 self._capture = IOManager(out=StdCapture(1), err=StdCapture(2))17 self._capture.start()18 def stop_capturing(self) -> None:19 if self._capture is not None:20 self._capture.finish()21 self._capture = None22 def resume_capture(self) -> None:23 if self._capture is not None:24 self._capture.resume()25 def read_capture(self):26 assert self._capture is not None27 return self._capture.read()28 def suspend_capture(self) -> None:29 self._capture.suspend()30 @contextlib.contextmanager...
test_warning.py
Source:test_warning.py
2mypath = py.path.local(__file__).new(ext=".py")3def test_forwarding_to_warnings_module():4 py.test.deprecated_call(py.log._apiwarn, "1.3", "..")5def test_apiwarn_functional(recwarn):6 capture = py.io.StdCapture()7 py.log._apiwarn("x.y.z", "something", stacklevel=1)8 out, err = capture.reset()9 py.builtin.print_("out", out)10 py.builtin.print_("err", err)11 assert err.find("x.y.z") != -112 lno = py.code.getrawcode(test_apiwarn_functional).co_firstlineno + 213 exp = "%s:%s" % (mypath, lno)14 assert err.find(exp) != -115def test_stacklevel(recwarn):16 def f():17 py.log._apiwarn("x", "some", stacklevel=2)18 # 319 # 420 capture = py.io.StdCapture()21 f()22 out, err = capture.reset()23 lno = py.code.getrawcode(test_stacklevel).co_firstlineno + 624 warning = str(err)25 assert warning.find(":%s" % lno) != -126def test_stacklevel_initpkg_with_resolve(testdir, recwarn):27 testdir.makepyfile(modabc="""28 import py29 def f():30 py.log._apiwarn("x", "some", stacklevel="apipkg123")31 """)32 testdir.makepyfile(apipkg123="""33 def __getattr__():34 import modabc35 modabc.f()36 """)37 p = testdir.makepyfile("""38 import apipkg12339 apipkg123.__getattr__()40 """)41 capture = py.io.StdCapture()42 p.pyimport()43 out, err = capture.reset()44 warning = str(err)45 loc = 'test_stacklevel_initpkg_with_resolve.py:2'46 assert warning.find(loc) != -147def test_stacklevel_initpkg_no_resolve(recwarn):48 def f():49 py.log._apiwarn("x", "some", stacklevel="apipkg")50 capture = py.io.StdCapture()51 f()52 out, err = capture.reset()53 lno = py.code.getrawcode(test_stacklevel_initpkg_no_resolve).co_firstlineno + 254 warning = str(err)55 assert warning.find(":%s" % lno) != -156def test_function(recwarn):57 capture = py.io.StdCapture()58 py.log._apiwarn("x.y.z", "something", function=test_function)59 out, err = capture.reset()60 py.builtin.print_("out", out)61 py.builtin.print_("err", err)62 assert err.find("x.y.z") != -163 lno = py.code.getrawcode(test_function).co_firstlineno64 exp = "%s:%s" % (mypath, lno)...
t3.py
Source:t3.py
1## Test the EWF reading capabililties2import pyaff4, pdb3import time4time.sleep(1)5oracle = pyaff4.Resolver()6urn = pyaff4.RDFURN()7try:8 urn.set("ewf:///var/tmp/uploads/stdcapture_0.4.pcap/stream")9 fd = oracle.open(urn, 'r')10 print fd11 fd.cache_return()12except RuntimeError:13 pass14urn.set("/var/tmp/uploads/stdcapture_0.4.pcap.e01")15if oracle.load(urn):16 print "Loaded URN %s" % urn.value17 ## Now list all the members in this volume18 stream_urn = pyaff4.RDFURN()19 iter = oracle.get_iter(urn, pyaff4.AFF4_CONTAINS)20 while oracle.iter_next(iter, stream_urn):21 print "Stream %s" % stream_urn.value22 fd = oracle.open(stream_urn, 'r')...
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!!