def irunner(): """Set up an irunner instance for testing.""" target = runnable.TestRunner(name="TestRunner") local_runner = runners.LocalRunner() test_uids = ["test_1", "test_2", "test_3"] test_objs = [ multitest.MultiTest( name=uid, suites=[Suite()], test_filter=filtering.Filter(), test_sorter=ordering.NoopSorter(), stdout_style=defaults.STDOUT_STYLE, environment=[driver.Driver(name="mock_driver")], ) for uid in test_uids ] for test in test_objs: local_runner.add(test, test.uid()) target.resources.add(local_runner) with mock.patch("cheroot.wsgi.Server"): irunner = base.TestRunnerIHandler(target) irunner.setup() yield irunner irunner.teardown()
def api_env(example_report): """ Set up and yield a client object for the API and the interactive handler. """ mock_target = mock.MagicMock() mock_target.cfg.name = "Interactive API Test" ihandler = base.TestRunnerIHandler(target=mock_target) ihandler.report = example_report ihandler.run_all_tests = mock.MagicMock() ihandler.run_test = mock.MagicMock() ihandler.run_test_suite = mock.MagicMock() ihandler.run_test_case = mock.MagicMock() ihandler.run_test_case_param = mock.MagicMock() ihandler.start_test_resources = mock.MagicMock() ihandler.stop_test_resources = mock.MagicMock() # Add a couple of fake attachments. ihandler.report.attachments = { "attached_log.txt": "/path/to/attached_log.txt", "attached_image.png": "/path/to/attached_image.png", } app, _ = http.generate_interactive_api(ihandler) app.config["TESTING"] = True with app.test_client() as client: yield client, ihandler
def test_startup(): """Test initializing and running the interactive runner.""" target = runnable.TestRunner(name="TestRunner") mock_server = mock.MagicMock() with mock.patch( "cheroot.wsgi.Server", return_value=mock_server ), mock.patch( "testplan.runnable.interactive.reloader.ModuleReloader" ) as MockReloader: MockReloader.return_value = None irunner = base.TestRunnerIHandler(target) irunner.setup() assert irunner.target.runpath == default_runpath(target) mock_server.prepare.assert_called_once() mock_server.bind_addr = ("hostname", 1234) assert irunner.http_handler_info == mock_server.bind_addr irunner.run() mock_server.serve.assert_called_once() irunner.teardown()
def api_env(example_report): mock_target = mock.MagicMock() mock_target.cfg.name = "Interactive API Test" ihandler = base.TestRunnerIHandler(target=mock_target) ihandler.report = example_report mock_httphandler = mock.MagicMock() app, _ = http.generate_interactive_api(mock_httphandler, ihandler) app.config["TESTING"] = True with app.test_client() as client: yield client, mock_httphandler, ihandler
def test_run_all_tagged_tests(tags, num_of_suite_entries): """Test running all tests whose testcases are selected by tags.""" target = runnable.TestRunner(name="TestRunner") local_runner = LocalRunner() test_uids = ["test_1", "test_2", "test_3"] test_objs = [ multitest.MultiTest( name=uid, suites=[TaggedSuite()], test_filter=filtering.Tags({"simple": set(tags)}), test_sorter=ordering.NoopSorter(), stdout_style=defaults.STDOUT_STYLE, environment=[driver.Driver(name="mock_driver")], ) for uid in test_uids ] for test in test_objs: local_runner.add(test, test.uid()) target.resources.add(local_runner) with mock.patch("cheroot.wsgi.Server"), mock.patch( "testplan.runnable.interactive.reloader.ModuleReloader" ) as MockReloader: MockReloader.return_value = None irunner = base.TestRunnerIHandler(target) irunner.setup() irunner.run_all_tests(await_results=True) assert irunner.report.passed assert len(irunner.report.entries) == 3 for test_report in irunner.report: assert test_report.passed assert len(test_report.entries) == 1 assert len(test_report.entries[0].entries) == num_of_suite_entries assert len(test_report.entries[0].entries[-1].entries) == 3 irunner.teardown()
def api_env(example_report): """ Set up and yield a client object for the API and the interactive handler. """ mock_target = mock.MagicMock() mock_target.cfg.name = "Interactive API Test" ihandler = base.TestRunnerIHandler(target=mock_target) ihandler.report = example_report ihandler.run_all_tests = mock.MagicMock() ihandler.run_test = mock.MagicMock() ihandler.run_test_suite = mock.MagicMock() ihandler.run_test_case = mock.MagicMock() ihandler.run_test_case_param = mock.MagicMock() ihandler.start_test_resources = mock.MagicMock() ihandler.stop_test_resources = mock.MagicMock() app, _ = http.generate_interactive_api(ihandler) app.config["TESTING"] = True with app.test_client() as client: yield client, ihandler