How to use pytest_terminal_summary method in Pytest

Best Python code snippet using pytest

spydist.py

Source:spydist.py Github

copy

Full Screen

...97 trace("master: interrupted")98 getattr(conn.root, "shutdown")()99 time.sleep(5)100 os._exit(0)101 def pytest_terminal_summary(self, terminalreporter):102 debug("master: pytest_terminal_summary", terminalreporter)103class BatchSlave(object):104 def __init__(self, config, logs_path):105 self.config = config106 self.items = []107 self.logs_path = logs_path108 @pytest.mark.trylast109 def pytest_sessionstart(self, session):110 debug("slave: pytest_sessionstart", session)111 def pytest_sessionfinish(self, session):112 debug("slave: pytest_sessionfinish", session)113 @pytest.hookimpl(trylast=True)114 def pytest_collection_modifyitems(self, session, config, items):115 debug("slave: pytest_collection_modifyitems", session, config, items)116 self.items = items117 def pytest_runtestloop(self):118 def search_nodeid(entries, nodeid):119 for ent in entries:120 if nodeid == ent.nodeid:121 return ent122 return None123 def finish_test(item):124 getattr(conn.root, "finish_test")(item.nodeid)125 def get_test(entries):126 while 1:127 nodeid = getattr(conn.root, "get_test")()128 if not nodeid:129 break130 item = search_nodeid(entries, nodeid)131 if item:132 return item133 return None134 # connect to batch server135 conn = None136 for _ in range(0, 10):137 try:138 filename = os.path.join(self.logs_path, "..", "batch.server")139 lines = utils.read_lines(filename)140 port = int(lines[0])141 conn = rpyc.connect("127.0.0.1", port)142 if conn and conn.root:143 break144 time.sleep(2)145 except Exception as exp:146 print("connect to batch server", exp, filename, port)147 time.sleep(2)148 try:149 item_list = []150 # wait for master ready151 is_ready = getattr(conn.root, "is_ready")152 while not is_ready(os.getpid()):153 trace("slave: waiting for master")154 time.sleep(2)155 # get first item156 item = get_test(self.items)157 if item:158 item_list.append(item)159 while 1:160 # check if there is some thing to do161 if not item_list:162 break163 # get next item164 item = get_test(self.items)165 if item:166 item_list.append(item)167 # get the item and next for the current execution168 [item, nextitem] = [item_list.pop(0), None]169 if item_list:170 nextitem = item_list[-1]171 debug("slave: pytest_runtestloop", item, nextitem)172 self.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)173 finish_test(item)174 except KeyboardInterrupt:175 trace("slave: interrupted")176 conn.close()177 trace("")178 os._exit(0)179 def pytest_terminal_summary(self, terminalreporter):180 debug("slave: pytest_terminal_summary", terminalreporter)181def get_impl_type():182 return 0 # not yet supported183 #new_bach_run = env.get("SPYTEST_BATCH_RUN_NEW")184 #if new_bach_run == "2":185 #return 2186 #return 1 if bool(new_bach_run) else 0187def shutdown():188 if get_impl_type() == 0:189 return190 if wa.server: wa.server.stop()191 if wa.service: wa.service.close()192def slave_main(index, testbed_file, logs_path):193 os.environ["PYTEST_XDIST_WORKER"] = str(index)...

Full Screen

Full Screen

test_plugin.py

Source:test_plugin.py Github

copy

Full Screen

...62 options = parser.getgroup("terminal reporting").options63 assert options[0].names() == ["--timer-top-n"]64 assert options[1].names() == ["--timer-no-color"]65 assert options[2].names() == ["--timer-filter"]66 def test_pytest_terminal_summary(self, mocker, tr_mock):67 plugin.pytest_terminal_summary(terminalreporter=tr_mock)68 tr_mock.write_line.assert_has_calls(69 [70 mocker.call("[success] 60.08% 1: 3.0100s"),71 mocker.call("[success] 20.16% 2: 1.0100s"),72 mocker.call("[success] 19.76% 3: 0.9900s"),73 ]74 )75 def test_pytest_terminal_summary_with_timer_top_n(self, mocker, tr_mock):76 tr_mock.config.option.timer_top_n = 177 plugin.pytest_terminal_summary(terminalreporter=tr_mock)78 tr_mock.write_line.assert_has_calls(79 [mocker.call("[success] 60.08% 1: 3.0100s")]80 )81 def test_pytest_terminal_summary_with_timer_filter_error(self, mocker, tr_mock):82 tr_mock.config.option.timer_filter = "error"83 plugin.pytest_terminal_summary(terminalreporter=tr_mock)84 tr_mock.write_line.assert_has_calls(85 [mocker.call("[success] 60.08% 1: 3.0100s")]86 )87 def test_pytest_terminal_summary_with_timer_filter_warning(self, mocker, tr_mock):88 tr_mock.config.option.timer_filter = "warning"89 plugin.pytest_terminal_summary(terminalreporter=tr_mock)90 tr_mock.write_line.assert_has_calls(91 [mocker.call("[success] 20.16% 2: 1.0100s")]92 )93 def test_pytest_terminal_summary_with_timer_filter_error_warning(94 self, mocker, tr_mock95 ):96 tr_mock.config.option.timer_filter = "error,warning"97 plugin.pytest_terminal_summary(terminalreporter=tr_mock)98 tr_mock.write_line.assert_has_calls(99 [100 mocker.call("[success] 60.08% 1: 3.0100s"),101 mocker.call("[success] 20.16% 2: 1.0100s"),102 ]103 )104 def test_pytest_terminal_summary_with_user_warning(self, mocker, tr_mock):105 warnings.warn("Test Warning to be used in tests")106 plugin.pytest_terminal_summary(terminalreporter=tr_mock)107 tr_mock.write_line.assert_has_calls(108 [109 mocker.call("[success] 60.08% 1: 3.0100s"),110 mocker.call("[success] 20.16% 2: 1.0100s"),111 mocker.call("[success] 19.76% 3: 0.9900s"),112 ]...

Full Screen

Full Screen

test_terminal_report.py

Source:test_terminal_report.py Github

copy

Full Screen

...38 def test_TerminalSummary_NoErrorsNoFailures_EmptyReport(self, mock_add_commands):39 mock_report = mock.MagicMock()40 mock_report.stats.get.return_value = []41 mock_config = mock.MagicMock()42 terminal_report.pytest_terminal_summary(mock_report, 0, mock_config)43 mock_add_commands.assert_not_called()44 mock_report.config.getoption.assert_not_called()45 mock_report.section.assert_not_called()46 @mock.patch('ly_test_tools._internal.pytest_plugin.terminal_report._add_commands')47 def test_TerminalSummary_ErrorsAndFailures_SectionsAdded(self, mock_add_commands):48 mock_report = mock.MagicMock()49 mock_node = mock.MagicMock()50 mock_node.nodeid = 'something'51 mock_report.stats.get.return_value = [mock_node, mock_node]52 mock_config = mock.MagicMock()53 terminal_report.pytest_terminal_summary(mock_report, 0, mock_config)54 assert len(mock_add_commands.mock_calls) == 255 mock_report.config.getoption.assert_called()56 mock_report.section.assert_called_once()57 @mock.patch('ly_test_tools._internal.pytest_plugin.terminal_report._add_commands', mock.MagicMock())58 @mock.patch('os.path.basename')59 def test_TerminalSummary_Failures_CallsWithBasename(self, mock_basename):60 mock_report = mock.MagicMock()61 mock_node = mock.MagicMock()62 mock_base = 'something'63 node_id = os.path.join('C:', mock_base)64 mock_node.nodeid = node_id65 mock_report.stats.get.side_effect = [[mock_node], []] # first item is failure list66 mock_config = mock.MagicMock()67 terminal_report.pytest_terminal_summary(mock_report, 0, mock_config)68 mock_basename.assert_called_with(node_id)69 @mock.patch('ly_test_tools._internal.pytest_plugin.terminal_report._add_commands', mock.MagicMock())70 @mock.patch('os.path.basename')71 def test_TerminalSummary_Errors_CallsWithBasename(self, mock_basename):72 mock_report = mock.MagicMock()73 mock_node = mock.MagicMock()74 mock_base = 'something'75 node_id = os.path.join('C:', mock_base)76 mock_node.nodeid = node_id77 mock_report.stats.get.side_effect = [[], [mock_node]] # second item is error list78 mock_config = mock.MagicMock()79 terminal_report.pytest_terminal_summary(mock_report, 0, mock_config)...

Full Screen

Full Screen

travis_fold.py

Source:travis_fold.py Github

copy

Full Screen

...4import pytest5fold_plugins = {'_cov': 'Coverage report', 'flaky': 'Flaky report'}6def terminal_summary_wrapper(original, plugin_name):7 text = fold_plugins[plugin_name]8 def pytest_terminal_summary(terminalreporter):9 terminalreporter.write('travis_fold:start:plugin.{}\n{}\n'.format(plugin_name, text))10 original(terminalreporter)11 terminalreporter.write('travis_fold:end:plugin.{}\n'.format(plugin_name))12 return pytest_terminal_summary13@pytest.mark.trylast14def pytest_configure(config):15 for hookimpl in config.pluginmanager.hook.pytest_terminal_summary._nonwrappers:16 if hookimpl.plugin_name in fold_plugins.keys():17 hookimpl.function = terminal_summary_wrapper(hookimpl.function,18 hookimpl.plugin_name)19terminal = None20previous_name = None21failed = set()22durations = defaultdict(int)...

Full Screen

Full Screen

Pytest Tutorial

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.

Chapters

  1. What is pytest
  2. Pytest installation: Want to start pytest from scratch? See how to install and configure pytest for Python automation testing.
  3. Run first test with pytest framework: Follow this step-by-step tutorial to write and run your first pytest script.
  4. Parallel testing with pytest: A hands-on guide to parallel testing with pytest to improve the scalability of your test automation.
  5. Generate pytest reports: Reports make it easier to understand the results of pytest-based test runs. Learn how to generate pytest reports.
  6. Pytest Parameterized tests: Create and run your pytest scripts while avoiding code duplication and increasing test coverage with parameterization.
  7. Pytest Fixtures: Check out how to implement pytest fixtures for your end-to-end testing needs.
  8. Execute Multiple Test Cases: Explore different scenarios for running multiple test cases in pytest from a single file.
  9. Stop Test Suite after N Test Failures: See how to stop your test suite after n test failures in pytest using the @pytest.mark.incremental decorator and maxfail command-line option.

YouTube

Skim our below pytest tutorial playlist to get started with automation testing using the pytest framework.

https://www.youtube.com/playlist?list=PLZMWkkQEwOPlcGgDmHl8KkXKeLF83XlrP

Run Pytest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful