Best Python code snippet using pytest
test_listener.py
Source:test_listener.py
2from six.moves import mock3from delayed_assert import expect, assert_expectations4import pytest5from pytest_reportportal.listener import RPReportListener6def test_pytest_runtest_protocol(mocked_item):7 """Test listener pytest_runtest_protocol hook.8 :param mocked_item: Pytest fixture9 """10 rp_service = mock.Mock()11 rp_service.is_item_update_supported = mock.Mock(return_value=False)12 rp_listener = RPReportListener(rp_service)13 rp_listener._add_issue_id_marks = mock.Mock()14 next(rp_listener.pytest_runtest_protocol(mocked_item))15 expect(rp_listener._add_issue_id_marks.call_count == 1,16 '_add_issue_id_marks called more than 1 time')17 assert_expectations()18def test_add_issue_info(rp_listener, rp_service):19 """Test listener helper _add_issue_info method.20 :param rp_listener: Pytest fixture21 :param rp_service: Pytest fixture22 """23 rp_service._issue_types = {"TST": "TEST"}24 report = mock.Mock()25 report.when = "call"26 report.skipped = False27 def getini(option):28 if option == "rp_issue_system_url":...
travis_fold.py
Source:travis_fold.py
...31 if rep.failed:32 global failed33 failed.add(name)34@pytest.hookimpl(hookwrapper=True, tryfirst=True)35def pytest_runtest_protocol(item, nextitem):36 # This is naughty but pytests' own plugins does something similar too, so who cares37 global terminal38 if terminal is None:39 terminal = _pytest.config.create_terminal_writer(item.config)40 global previous_name41 name = _get_name(item.location)42 if previous_name is None or previous_name != name:43 previous_name = name44 terminal.write('\ntravis_fold:start:{}\r'.format(name.split('::')[1]))45 terminal.write('travis_time:start:{}time\r'.format(name.split('::')[1]))46 terminal.write(name)47 yield48 if nextitem is None or _get_name(nextitem.location) != name:49 global failed...
pytest_elasticapm.py
Source:pytest_elasticapm.py
...35 client.begin_transaction(transaction_type=session.name)36def pytest_sessionfinish(session: pytest.Session, exitstatus: Union[int, pytest.ExitCode]) -> None:37 client = _apm_client()38 client.end_transaction(name=session.name)39#def pytest_runtest_protocol(item: pytest.Item, nextitem: Optional[pytest.Item]) -> Optional[object]:40# pass41@pytest.hookimpl(hookwrapper=True)42def pytest_runtest_protocol(item: pytest.Item, nextitem: Optional[pytest.Item]):43 with e_.capture_span(item.name):44 print("sending")45 yield46def pytest_report_teststatus(report: Union[CollectReport, TestReport], config: Config):47 if report.outcome == "failed":48 # FIXME might need to make sure we are in a specific test transaction...
plugin.py
Source:plugin.py
...18 policy = item.config.getoption('--pcap-retention')19 capture.preserve = bool(policy == 'always')20 return capture21@pytest.hookimpl(hookwrapper=True)22def pytest_runtest_protocol(item, nextitem):23 capture = setup_capture(item)24 item.config.capture = capture25 yield26 if capture:27 capture.stop()28 pytest.log.info('{} recieved by filter, '29 '{} dropped by kernel'.format(*capture.stats))30 if not capture.preserve:31 capture.delete()32def pytest_runtest_makereport(item, call):33 capture = getattr(item.config, 'capture', None)34 if not capture:35 return36 policy = item.config.getoption('--pcap-retention')...
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!!