def test_single_skipped_test(self): with keep_counts() as current_count, skip_if(True): @test() def _(): pass self.assertEqual(current_count(), Counts(0, 0, 1))
def test_single_passing_test(self): with keep_counts() as current_count: @test() def _(): pass self.assertEqual(current_count(), Counts(1, 0, 0))
def test_single_failing_test(self): with keep_counts() as current_count: @test() def _(): fail() self.assertEqual(current_count(), Counts(0, 1, 0))
def _test_command(args): ''' Runs when using test command ''' with keep_score() as current_score, keep_counts() as current_counts: def report_fail(e): message = "\n".join([ f'[{current_counts().test_index}] FAIL {str(e)}', *[ f'{key}: {value}' for key, value in current_context().items() ], '=' * 50, ]) print(message.strip()) with reporting(on_fail=report_fail): for path_to_tests in find_files_recursively( predicate=has_name(args.tests_file)): directory_containing_tests = os.path.dirname(path_to_tests) with inside_directory(directory_containing_tests): tested_file_present = os.path.isfile(args.tested_file) filename_of_tests = os.path.basename(path_to_tests) if not tested_file_present: print( f"ERROR: Could not find {args.tested_file} in {os.path.abspath(directory_containing_tests)}" ) if args.ignore_missing_tested_file: print( f"WARNING: Continuing with testing --- tests will be fully ignored, not even be counted as skipped" ) else: sys.exit(-1) else: with tested_file(args.tested_file), context( 'Tests directory', directory_containing_tests): execute_code(os.path.basename(filename_of_tests)) score = current_score() counts = current_counts() print(f'PASS {counts.npass}') print(f'FAIL {counts.nfail}') print(f'SKIP {counts.nskip}') print(f'Score: {score}')
def test_skip_after_fail_pff(self): with keep_counts() as current_count, skip_after_fail(): @test() def _(): pass @test() def _(): fail() @test() def _(): fail() self.assertEqual(current_count(), Counts(1, 1, 1))
def test_skip_after_fail_ppp(self): with keep_counts() as current_count, skip_after_fail(): @test() def _(): pass @test() def _(): pass @test() def _(): pass self.assertEqual(current_count(), Counts(3, 0, 0))
def test_continue_after_fail_fpp(self): with keep_counts() as current_count, continue_after_fail(): @test() def _(): fail() @test() def _(): pass @test() def _(): pass self.assertEqual(current_count(), Counts(2, 1, 0))
def test_all_or_nothing_fpp(self): with keep_score(), keep_counts() as current_count, all_or_nothing(): @test() def _(): fail() @test() def _(): pass @test() def _(): pass self.assertEqual(current_count(), Counts(2, 1, 0))