Skip to content

Commit 5b0cf3b

Browse files
committed
Add more tests
1 parent 105f910 commit 5b0cf3b

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

tests/integration/test_fixtures.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,128 @@ def test_failure_fixture_teardown(mock_client_init):
419419
assert log_call_kwargs['item_id'] == \
420420
('examples/fixtures/test_failure_fixture_teardown/test_failure_fixture_teardown.py::'
421421
'test_failure_fixture_teardown_1')
422+
423+
424+
@mock.patch(REPORT_PORTAL_SERVICE)
425+
def test_session_fixture_setup(mock_client_init):
426+
mock_client = mock_client_init.return_value
427+
mock_client.step_reporter = StepReporter(mock_client)
428+
429+
variables = dict(utils.DEFAULT_VARIABLES)
430+
variables['rp_report_fixtures'] = True
431+
result = utils.run_pytest_tests(tests=['examples/fixtures/session_fixture_return'], variables=variables)
432+
assert int(result) == 0, 'Exit code should be 0 (no errors)'
433+
434+
start_count = mock_client.start_test_item.call_count
435+
finish_count = mock_client.finish_test_item.call_count
436+
assert start_count == finish_count == 4, 'Incorrect number of "start_test_item" or "finish_test_item" calls'
437+
438+
call_args = mock_client.start_test_item.call_args_list
439+
setup_call_args = call_args[1][0]
440+
step_name = 'session fixture setup: session_fixture_return_config'
441+
assert setup_call_args[0] == step_name
442+
443+
setup_call_kwargs = call_args[1][1]
444+
assert not setup_call_kwargs['has_stats']
445+
446+
teardown_call_args = call_args[-1][0]
447+
assert teardown_call_args[0] == 'session fixture teardown: session_fixture_return_config'
448+
449+
setup_call_kwargs = call_args[-1][1]
450+
assert not setup_call_kwargs['has_stats']
451+
452+
453+
@mock.patch(REPORT_PORTAL_SERVICE)
454+
def test_package_fixture_setup(mock_client_init):
455+
mock_client = mock_client_init.return_value
456+
mock_client.step_reporter = StepReporter(mock_client)
457+
458+
variables = dict(utils.DEFAULT_VARIABLES)
459+
variables['rp_report_fixtures'] = True
460+
result = utils.run_pytest_tests(tests=['examples/fixtures/package_fixture_return'], variables=variables)
461+
assert int(result) == 0, 'Exit code should be 0 (no errors)'
462+
463+
start_count = mock_client.start_test_item.call_count
464+
finish_count = mock_client.finish_test_item.call_count
465+
assert start_count == finish_count == 4, 'Incorrect number of "start_test_item" or "finish_test_item" calls'
466+
467+
call_args = mock_client.start_test_item.call_args_list
468+
setup_call_args = call_args[1][0]
469+
step_name = 'package fixture setup: package_fixture_return_config'
470+
assert setup_call_args[0] == step_name
471+
472+
setup_call_kwargs = call_args[1][1]
473+
assert not setup_call_kwargs['has_stats']
474+
475+
teardown_call_args = call_args[-1][0]
476+
assert teardown_call_args[0] == 'package fixture teardown: package_fixture_return_config'
477+
478+
setup_call_kwargs = call_args[-1][1]
479+
assert not setup_call_kwargs['has_stats']
480+
481+
482+
@mock.patch(REPORT_PORTAL_SERVICE)
483+
def test_module_fixture_setup(mock_client_init):
484+
mock_client = mock_client_init.return_value
485+
mock_client.step_reporter = StepReporter(mock_client)
486+
487+
variables = dict(utils.DEFAULT_VARIABLES)
488+
variables['rp_report_fixtures'] = True
489+
result = utils.run_pytest_tests(tests=['examples/fixtures/module_fixture_return'], variables=variables)
490+
assert int(result) == 0, 'Exit code should be 0 (no errors)'
491+
492+
start_count = mock_client.start_test_item.call_count
493+
finish_count = mock_client.finish_test_item.call_count
494+
assert start_count == finish_count == 4, 'Incorrect number of "start_test_item" or "finish_test_item" calls'
495+
496+
call_args = mock_client.start_test_item.call_args_list
497+
setup_call_args = call_args[1][0]
498+
step_name = 'module fixture setup: module_fixture_return_config'
499+
assert setup_call_args[0] == step_name
500+
501+
setup_call_kwargs = call_args[1][1]
502+
assert not setup_call_kwargs['has_stats']
503+
504+
teardown_call_args = call_args[-1][0]
505+
assert teardown_call_args[0] == 'module fixture teardown: module_fixture_return_config'
506+
507+
setup_call_kwargs = call_args[-1][1]
508+
assert not setup_call_kwargs['has_stats']
509+
510+
511+
@mock.patch(REPORT_PORTAL_SERVICE)
512+
def test_class_fixture_setup(mock_client_init):
513+
mock_client = mock_client_init.return_value
514+
mock_client.step_reporter = StepReporter(mock_client)
515+
516+
variables = dict(utils.DEFAULT_VARIABLES)
517+
variables['rp_report_fixtures'] = True
518+
result = utils.run_pytest_tests(tests=['examples/fixtures/class_fixture_return'], variables=variables)
519+
assert int(result) == 0, 'Exit code should be 0 (no errors)'
520+
521+
start_count = mock_client.start_test_item.call_count
522+
finish_count = mock_client.finish_test_item.call_count
523+
assert start_count == finish_count == 8, 'Incorrect number of "start_test_item" or "finish_test_item" calls'
524+
525+
call_args = mock_client.start_test_item.call_args_list
526+
setup_call_args = call_args[1][0]
527+
step_name = 'class fixture setup: class_fixture_return_config'
528+
assert setup_call_args[0] == step_name
529+
setup_call_kwargs = call_args[1][1]
530+
assert not setup_call_kwargs['has_stats']
531+
532+
setup_call_args = call_args[-3][0]
533+
assert setup_call_args[0] == step_name
534+
setup_call_kwargs = call_args[-3][1]
535+
assert not setup_call_kwargs['has_stats']
536+
537+
teardown_step_name = 'class fixture teardown: class_fixture_return_config'
538+
teardown_call_args = call_args[-5][0]
539+
assert teardown_call_args[0] == teardown_step_name
540+
setup_call_kwargs = call_args[-5][1]
541+
assert not setup_call_kwargs['has_stats']
542+
543+
teardown_call_args = call_args[-1][0]
544+
assert teardown_call_args[0] == teardown_step_name
545+
setup_call_kwargs = call_args[-1][1]
546+
assert not setup_call_kwargs['has_stats']

0 commit comments

Comments
 (0)