def test_class_method_setup_fail(testdir): test_file = 'fixtures/test_class_method_setup_fail.py' (result, scheduler) = run_test(testdir, [test_file]) assert_outcomes(result, error=1) assert scheduler.suite_items == [ SuiteItem( 'class', Location(test_file, module_for(test_file), 'TestObject', None, 1)), SuiteItem('file', Location(test_file), size=42), SuiteItem('setup', Location(test_file, module_for(test_file), 'TestObject', 'setup_method', 3), scope='method'), SuiteItem( 'test', Location(test_file, module_for(test_file), 'TestObject', 'test', 6)), ] assert scheduler.report_items == [ ReportItem( 'setup', Location(test_file, module_for(test_file), 'TestObject', 'setup_method', 3), 'failed', Failure('Exception', 'setup failed')), ReportItem( 'test', Location(test_file, module_for(test_file), 'TestObject', 'test', 6), 'failed'), ]
def test_fixture_fail(testdir): test_file = 'fixtures/test_fixture_fail.py' (result, scheduler) = run_test(testdir, [test_file]) assert_outcomes(result, error=1) assert scheduler.suite_items == [ SuiteItem('file', Location(test_file), size=42), SuiteItem( 'fixture', Location(test_file, module_for(test_file), None, 'fixture', 4)), SuiteItem('test', Location(test_file, module_for(test_file), None, 'test_with_fixture', 9), deps=[ SuiteItem( 'fixture', Location(test_file, module_for(test_file), None, 'fixture', 4)), ]), ] assert scheduler.report_items == [ ReportItem( 'setup', Location(test_file, module_for(test_file), None, 'fixture', 4), 'error', Failure('Exception', 'setup failed')), ReportItem( 'teardown', Location(test_file, module_for(test_file), None, 'fixture', 4), 'passed'), ReportItem( 'test', Location(test_file, module_for(test_file), None, 'test_with_fixture', 9), 'failed'), ]
def test_function_xfail(testdir): test_file = 'fixtures/test_function_xfail.py' (result, scheduler) = run_test(testdir, [test_file]) assert_outcomes(result, passed=0) assert scheduler.report_items == [ ReportItem( 'test', Location(test_file, module_for(test_file), None, 'test_xfail', 4), 'skipped', Failure('AssertionError', 'assert (1 + 2) == 12')), ]
def test_function_setup_fail(testdir): test_file = 'fixtures/test_function_setup_fail.py' (result, scheduler) = run_test(testdir, [test_file]) assert_outcomes(result, error=1) assert scheduler.report_items == [ ReportItem( 'setup', Location(test_file, module_for(test_file), None, 'setup_function', 1), 'failed', Failure('Exception', 'setup failed')), ReportItem('test', Location(test_file, module_for(test_file), None, 'test', 5), 'failed'), ]
def test_class_method_teardown_fail(testdir): test_file = 'fixtures/test_class_method_teardown_fail.py' (result, scheduler) = run_test(testdir, [test_file]) assert_outcomes(result, error=1, passed=1) assert scheduler.report_items == [ ReportItem( 'teardown', Location(test_file, module_for(test_file), 'TestObject', 'teardown_method', 3), 'failed', Failure('Exception', 'teardown failed')), ReportItem( 'test', Location(test_file, module_for(test_file), 'TestObject', 'test', 6), 'passed'), ]
async def test_successful_server_communication(config, mock_server): os.environ['MY_CI'] = 'true' settings = MockSettings({ 'api_domain': mock_server.url, 'api_key': 'api_key', 'api_retry_limit': '1', 'api_wait_limit': '0', 'build_dir': '/app', 'build_id': config['build']['id'], 'build_job': 'job', 'enabled': True, 'vcs_branch': 'master', 'vcs_repo': 'github.com/myrepo', 'vcs_revision': 'asd43da', 'vcs_revision_message': 'my commit', }) client = Client(settings) client.subscribe(settings) suite_items = [ SuiteItem( 'test', Location('tests/IT/stub/stub_A.py', 'stub_A', 'TestClass', 'test_A', 1)), SuiteItem('test', Location('tests/IT/stub/stub_B.py', 'stub_B', 'TestClass', 'test_B', 1), tags=[Tag('my_group', False)]), SuiteItem('test', Location('tests/IT/stub/stub_C.py', 'stub_C', 'TestClass', 'test_C', 1), deps=[ SuiteItem( 'fixture', Location('tests/IT/stub/stub_fixture.py', 'fixtures', 'FixtureClass', 'test_C', 0)), ]), ] scheduler = Scheduler(settings, client, suite_items, 'my_worker_id') # (1) CONNECT await client.start() # (2) SERVER REQUESTS ENV await mock_server.send(MessageType.Envs, [{ 'name': 'CI', 'conditions': ['my_CI'], 'mapping': {} }]) # (3) CLIENT REPLIES WITH ENV await assert_received_eventually(mock_server, [ (MessageType.Envs.value, 'CI'), (MessageType.Ack.value, { 'message_num': 0, 'status': 'success' }), ]) # (4) SERVER REQUESTS CONFIG await mock_server.send(MessageType.Config, {}) # (5) CLIENT REPLIES WITH CONFIG await assert_received_eventually(mock_server, [ (MessageType.Config.value, { 'build': { 'dir': '/app', 'id': config['build']['id'], 'job': 'job', 'node': 'random-uuid', 'pool': 0, 'project': None, 'url': None }, 'client': { 'capabilities': ['fixtures', 'lifecycle_timings', 'split_by_file'], 'messages': [ 'ack', 'config', 'done', 'envs', 'error', 'report', 'schedules', 'suite' ], 'name': 'pytest-conquer', 'version': '1.0', 'workers': 1, 'worker_id': 'my_worker_id', }, 'platform': { 'name': 'python', 'version': '3.6' }, 'runner': { 'args': ['arg1'], 'name': None, 'plugins': [], 'root': None, 'version': None }, 'system': { 'context': {}, 'cpus': 3, 'os': 'Linux', 'os_version': '1.42', 'provider': 'CI', 'ram': 17179869184 }, 'vcs': { 'branch': 'master', 'pr': None, 'repo': 'github.com/myrepo', 'revision': 'asd43da', 'revision_message': 'my commit', 'tag': None, 'type': 'git' }, }), (MessageType.Ack.value, { 'message_num': 1, 'status': 'success' }), ]) # (6) SERVER REQUESTS SUITE await mock_server.send(MessageType.Suite, {}) # (7) CLIENT SENDS SUITE await assert_received_eventually(mock_server, [ (MessageType.Suite.value, { 'items': [ { 'type': 'test', 'location': { 'file': 'tests/IT/stub/stub_A.py', 'func': 'test_A', 'module': 'stub_A', 'class': 'TestClass', 'line': 1 } }, { 'type': 'test', 'location': { 'file': 'tests/IT/stub/stub_B.py', 'func': 'test_B', 'module': 'stub_B', 'class': 'TestClass', 'line': 1 }, 'tags': [{ 'group': 'my_group' }] }, { 'type': 'test', 'location': { 'file': 'tests/IT/stub/stub_C.py', 'func': 'test_C', 'module': 'stub_C', 'class': 'TestClass', 'line': 1 }, 'deps': [{ 'type': 'fixture', 'location': { 'file': 'tests/IT/stub/stub_fixture.py', 'func': 'test_C', 'module': 'fixtures', 'class': 'FixtureClass' } }] }, ], }), (MessageType.Ack.value, { 'message_num': 2, 'status': 'success' }), ]) # (8) SERVER SENDS SCHEDULE #1 await mock_server.send(MessageType.Schedules, [{ 'id': '0', 'items': [ { 'file': 'tests/IT/stub/stub_A.py' }, { 'file': 'tests/IT/stub/stub_B.py' }, ], }]) await assert_received_eventually(mock_server, [ (MessageType.Ack.value, { 'message_num': 3, 'status': 'success' }), ]) assert await scheduler.next() == Schedule('0', [ ScheduleItem('tests/IT/stub/stub_A.py'), ScheduleItem('tests/IT/stub/stub_B.py'), ]) # (9) CLIENT SENDS REPORT #1 await scheduler.report( Report('0', [ ReportItem( 'test', Location('tests/IT/stub/stub_A.py', 'stub_A', 'TestClass', 'test_A', 3), 'failed', Failure('AssertionError', 'assert 1 + 1 == 4'), time, time), ReportItem( 'test', Location('tests/IT/stub/stub_B.py', 'stub_B', 'TestClass', 'test_B', 1), 'passed', None, time, time), ], time, time, time)) await assert_received_eventually(mock_server, [ (MessageType.Ack.value, { 'schedule_id': '0', 'status': 'success' }), (MessageType.Report.value, { 'schedule_id': '0', 'items': [{ 'type': 'test', 'location': { 'file': 'tests/IT/stub/stub_A.py', 'func': 'test_A', 'module': 'stub_A', 'class': 'TestClass', 'line': 3 }, 'status': 'failed', 'started_at': '2000-01-01T00:00:00.000Z', 'finished_at': '2000-01-01T00:00:00.000Z', 'error': { 'type': 'AssertionError', 'message': 'assert 1 + 1 == 4' }, }, { 'type': 'test', 'location': { 'file': 'tests/IT/stub/stub_B.py', 'func': 'test_B', 'module': 'stub_B', 'class': 'TestClass', 'line': 1 }, 'status': 'passed', 'started_at': '2000-01-01T00:00:00.000Z', 'finished_at': '2000-01-01T00:00:00.000Z', }], 'pending_at': '2000-01-01T00:00:00.000Z', 'started_at': '2000-01-01T00:00:00.000Z', 'finished_at': '2000-01-01T00:00:00.000Z', }), ]) # (10) SERVER SENDS SCHEDULE #2 await mock_server.send(MessageType.Schedules, [{ 'id': '1', 'items': [ { 'file': 'tests/IT/stub/stub_C.py' }, ], }]) await assert_received_eventually(mock_server, [ (MessageType.Ack.value, { 'message_num': 4, 'status': 'success' }), ]) assert await scheduler.next() == Schedule('1', [ ScheduleItem('tests/IT/stub/stub_C.py'), ]) # (12) CLIENT SENDS REPORT #2 await scheduler.report( Report('1', [ ReportItem( 'test', Location('tests/IT/stub/stub_C.py', 'stub_C', 'TestClass', 'test_C', 1), 'passed', None, time, time), ], time, time, time)) await assert_received_eventually(mock_server, [ (MessageType.Ack.value, { 'schedule_id': '1', 'status': 'success' }), (MessageType.Report.value, { 'schedule_id': '1', 'items': [{ 'type': 'test', 'location': { 'file': 'tests/IT/stub/stub_C.py', 'func': 'test_C', 'module': 'stub_C', 'class': 'TestClass', 'line': 1 }, 'status': 'passed', 'started_at': '2000-01-01T00:00:00.000Z', 'finished_at': '2000-01-01T00:00:00.000Z', }], 'pending_at': '2000-01-01T00:00:00.000Z', 'started_at': '2000-01-01T00:00:00.000Z', 'finished_at': '2000-01-01T00:00:00.000Z', }), ]) # (13) SERVER SENDS DONE await mock_server.send(MessageType.Done, {}) await asyncio.sleep(0.1) assert scheduler.more is False # (14) SHUTDOWN await scheduler.stop() await client.stop()
def to_failure(exc_info): if exc_info is None: return None exc_type, exc_obj, exc_tb = exc_info return Failure(exc_type.__name__, str(exc_obj))