Best Python code snippet using pytest
pydev_runfiles_pytest.py
Source:pydev_runfiles_pytest.py
...38 time_str = '%.2f' % (delta,)39 pydev_runfiles_xml_rpc.notifyTest(cond, captured_output, error_contents, filename, test, time_str)40 41 42 def __pytest_pycollect_makeitem(self, collector, name, obj):43 if not self.py_test_accept_filter:44 return self._original_pytest_collect_makeitem(collector, name, obj)45 46 f = _NormFile(collector.fspath.strpath)47 48 if f not in self.py_test_accept_filter:49 return50 51 tests = self.py_test_accept_filter[f]52 found_methods_starting = []53 for test in tests:54 55 if test == name:56 #Direct match of the test (just go on with the default loading)...
pytestplugin.py
Source:pytestplugin.py
...54 item.parent.parent.parent.name,55 item.parent.parent.name,56 item.name57 ))58def pytest_pycollect_makeitem(collector, name, obj):59 if inspect.isclass(obj) and plugin_base.want_class(obj):60 return pytest.Class(name, parent=collector)61 elif inspect.isfunction(obj) and \62 name.startswith("test_") and \63 isinstance(collector, pytest.Instance):64 return pytest.Function(name, parent=collector)65 else:66 return []67_current_class = None68def pytest_runtest_setup(item):69 # here we seem to get called only based on what we collected70 # in pytest_collection_modifyitems. So to do class-based stuff71 # we have to tear that out.72 global _current_class...
integration.py
Source:integration.py
...5class TestOEJSKITSpecials:6 def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage7 testdir.makeconftest("""8 import pytest9 def pytest_pycollect_makeitem(collector, name, obj):10 if name == "MyClass":11 return MyCollector(name, parent=collector)12 class MyCollector(pytest.Collector):13 def reportinfo(self):14 return self.fspath, 3, "xyz"15 """)16 modcol = testdir.getmodulecol("""17 def pytest_funcarg__arg1(request):18 return 4219 class MyClass:20 pass21 """)22 # this hook finds funcarg factories23 rep = modcol.ihook.pytest_make_collect_report(collector=modcol)24 clscol = rep.result[0]25 clscol.obj = lambda arg1: None26 clscol.funcargs = {}27 pytest._fillfuncargs(clscol)28 assert clscol.funcargs['arg1'] == 4229 def test_autouse_fixture(self, testdir): # rough jstests usage30 testdir.makeconftest("""31 import pytest32 def pytest_pycollect_makeitem(collector, name, obj):33 if name == "MyClass":34 return MyCollector(name, parent=collector)35 class MyCollector(pytest.Collector):36 def reportinfo(self):37 return self.fspath, 3, "xyz"38 """)39 modcol = testdir.getmodulecol("""40 import pytest41 @pytest.fixture(autouse=True)42 def hello():43 pass44 def pytest_funcarg__arg1(request):45 return 4246 class MyClass:...
pytestplugin.pyi
Source:pytestplugin.pyi
...11def pytest_collection_finish(session): ...12def pytest_configure_node(node) -> None: ...13def pytest_testnodedown(node, error) -> None: ...14def pytest_collection_modifyitems(session, config, items): ...15def pytest_pycollect_makeitem(collector, name, obj): ...16def pytest_runtest_setup(item) -> None: ...17def pytest_runtest_teardown(item, nextitem) -> None: ...18def pytest_runtest_call(item) -> None: ...19def pytest_runtest_logreport(report) -> None: ...20def setup_class_methods(request) -> None: ...21def setup_test_methods(request) -> None: ...22def getargspec(fn): ...23class PytestFixtureFunctions(plugin_base.FixtureFunctions):24 def skip_test_exception(self, *arg, **kw): ...25 def mark_base_test_class(self): ...26 def combinations(self, *arg_sets, **kw): ...27 def param_ident(self, *parameters): ...28 def fixture(self, *arg, **kw): ...29 def get_current_test_name(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!!