Best Python code snippet using pytest
test_faulthandler.py
Source:test_faulthandler.py
...13 )14 result = pytester.runpytest_subprocess()15 result.stderr.fnmatch_lines(["*Fatal Python error*"])16 assert result.ret != 017def setup_crashing_test(pytester: Pytester) -> None:18 pytester.makepyfile(19 """20 import faulthandler21 import atexit22 def test_ok():23 atexit.register(faulthandler._sigabrt)24 """25 )26def test_crash_during_shutdown_captured(pytester: Pytester) -> None:27 """28 Re-enable faulthandler if pytest encountered it enabled during configure.29 We should be able to then see crashes during interpreter shutdown.30 """31 setup_crashing_test(pytester)32 args = (sys.executable, "-Xfaulthandler", "-mpytest")33 result = pytester.run(*args)34 result.stderr.fnmatch_lines(["*Fatal Python error*"])35 assert result.ret != 036def test_crash_during_shutdown_not_captured(pytester: Pytester) -> None:37 """38 Check that pytest leaves faulthandler disabled if it was not enabled during configure.39 This prevents us from seeing crashes during interpreter shutdown (see #8260).40 """41 setup_crashing_test(pytester)42 args = (sys.executable, "-mpytest")43 result = pytester.run(*args)44 result.stderr.no_fnmatch_line("*Fatal Python error*")45 assert result.ret != 046def test_disabled(pytester: Pytester) -> None:47 """Test option to disable fault handler in the command line."""48 pytester.makepyfile(49 """50 import faulthandler51 def test_disabled():52 assert not faulthandler.is_enabled()53 """54 )55 result = pytester.runpytest_subprocess("-p", "no:faulthandler")...
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!!