Best Python code snippet using pytest
test_pdb.py
Source:test_pdb.py
1import sys2import _pytest._code3def runpdb_and_get_report(testdir, source):4 p = testdir.makepyfile(source)5 result = testdir.runpytest_inprocess("--pdb", p)6 reports = result.reprec.getreports("pytest_runtest_logreport")7 assert len(reports) == 3, reports # setup/call/teardown8 return reports[1]9class TestPDB:10 def pytest_funcarg__pdblist(self, request):11 monkeypatch = request.getfuncargvalue("monkeypatch")12 pdblist = []13 def mypdb(*args):14 pdblist.append(args)15 plugin = request.config.pluginmanager.getplugin('pdb')16 monkeypatch.setattr(plugin, 'post_mortem', mypdb)17 return pdblist18 def test_pdb_on_fail(self, testdir, pdblist):19 rep = runpdb_and_get_report(testdir, """20 def test_func():21 assert 022 """)23 assert rep.failed24 assert len(pdblist) == 125 tb = _pytest._code.Traceback(pdblist[0][0])26 assert tb[-1].name == "test_func"27 def test_pdb_on_xfail(self, testdir, pdblist):28 rep = runpdb_and_get_report(testdir, """29 import pytest30 @pytest.mark.xfail31 def test_func():32 assert 033 """)34 assert "xfail" in rep.keywords35 assert not pdblist36 def test_pdb_on_skip(self, testdir, pdblist):37 rep = runpdb_and_get_report(testdir, """38 import pytest39 def test_func():40 pytest.skip("hello")41 """)42 assert rep.skipped43 assert len(pdblist) == 044 def test_pdb_on_BdbQuit(self, testdir, pdblist):45 rep = runpdb_and_get_report(testdir, """46 import bdb47 def test_func():48 raise bdb.BdbQuit49 """)50 assert rep.failed51 assert len(pdblist) == 052 def test_pdb_interaction(self, testdir):53 p1 = testdir.makepyfile("""54 def test_1():55 i = 056 assert i == 157 """)58 child = testdir.spawn_pytest("--pdb %s" % p1)59 child.expect(".*def test_1")...
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!!