Best Python code snippet using pytest
runner.py
Source:runner.py
...6import unittest7from osgeo import gdal8from qgis.core import Qgis9from qgis.PyQt import Qt10def pytest_report_header(config):11 """Used by PyTest and Unittest."""12 message = "QGIS : {}\n".format(Qgis.QGIS_VERSION_INT)13 message += "Python GDAL : {}\n".format(gdal.VersionInfo("VERSION_NUM"))14 message += "Python : {}\n".format(sys.version)15 # message += 'Python path : {}'.format(sys.path)16 message += "QT : {}".format(Qt.QT_VERSION_STR)17 return message18def _run_tests(test_suite, package_name, pattern):19 """Core function to test a test suite.20 :param test_suite: Unittest test suite21 """22 count = test_suite.countTestCases()23 print("######## Environment ########")24 print(pytest_report_header(None))25 print("{} tests has been discovered in {} with pattern {}".format(count, package_name, pattern))26 print("######## Running tests ########")27 results = unittest.TextTestRunner(verbosity=2).run(test_suite)28 print("######## Summary ########")29 print("Errors : {}".format(len(results.errors)))30 print("Failures : {}".format(len(results.failures)))31 print("Expected failures : {}".format(len(results.expectedFailures)))32 print("Unexpected successes : {}".format(len(results.unexpectedSuccesses)))33 print("Skip : {}".format(len(results.skipped)))34 successes = (35 results.testsRun - (36 len(results.errors) + len(results.failures) + len(results.expectedFailures)37 + len(results.unexpectedSuccesses) + len(results.skipped)))38 print("Successes : {}".format(successes))...
test_runner.py
Source:test_runner.py
...9 :param test_suite: Unittest test suite10 """11 count = test_suite.countTestCases()12 print("######## Environment ########")13 print(pytest_report_header(None))14 print("{} tests has been discovered in {} with pattern {}".format(count, package_name, pattern))15 print("######## Running tests ########")16 results = unittest.TextTestRunner(verbosity=2).run(test_suite)17 print("######## Summary ########")18 print("Errors : {}".format(len(results.errors)))19 print("Failures : {}".format(len(results.failures)))20 print("Expected failures : {}".format(len(results.expectedFailures)))21 print("Unexpected successes : {}".format(len(results.unexpectedSuccesses)))22 print("Skip : {}".format(len(results.skipped)))23 successes = (24 results.testsRun - (25 len(results.errors) + len(results.failures) + len(results.expectedFailures)26 + len(results.unexpectedSuccesses) + len(results.skipped)))27 print("Successes : {}".format(successes))...
conftest.py
Source:conftest.py
1import io2import warnings3import pytest4def pytest_report_header(config):5 try:6 from PIL import features7 with io.StringIO() as out:8 features.pilinfo(out=out, supported_formats=False)9 return out.getvalue()10 except Exception as e:11 return f"pytest_report_header failed: {e}"12def pytest_configure(config):13 # We're marking some tests to ignore valgrind errors and XFAIL them.14 # Ensure that the mark is defined15 # even in cases where pytest-valgrind isn't installed16 with warnings.catch_warnings():17 warnings.simplefilter("error")18 try:...
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!!