def test_many_variables(capfd): a = 1 b = 4.3 c = 'hello world' log(a, b, c) fuction_name = 'test_many_variables' actual_output = capfd.readouterr().out expected_output = '' expected_output += make_log_line(fuction_name, 84, 'a', a) expected_output += make_log_line(fuction_name, 84, 'b', b) expected_output += make_log_line(fuction_name, 84, 'c', c) assert actual_output == expected_output
def test_object(capfd): class MyClass: def __init__(self, name): self.name = name def __repr__(self): return self.name my_object = MyClass('name') log(my_object) actual_output = capfd.readouterr().out expected_output = make_log_line('test_object', 131, 'my_object', my_object) assert actual_output == expected_output
def test_no_args_with_vars(capfd): a = 1 b = 4.3 c = 'hello world' log() fuction_name = 'test_no_args_with_vars' actual_output = capfd.readouterr().out actual_list = [item + '\n' for item in actual_output[:-1].split('\n')] expected_list = [] expected_list += [make_log_line(fuction_name, 98, 'a', a)] expected_list += [make_log_line(fuction_name, 98, 'b', b)] expected_list += [make_log_line(fuction_name, 98, 'c', c)] expected_list += [make_log_line(fuction_name, 98, 'capfd', capfd)] assert len(actual_list) == len(expected_list) assert set(actual_list) == set(expected_list)
def inner_function(): log()
def test_list_vars(capfd): log(var_list) actual_output = capfd.readouterr().out expected_output = make_log_line('test_list_vars', 74, 'var_list', var_list) assert actual_output == expected_output
def test_empty_string(capfd): log('') actual_output = capfd.readouterr().out expected_output = make_log_line('test_empty_string', 67, None, '') assert actual_output == expected_output
def test_literal_string(capfd): log('testing') actual_output = capfd.readouterr().out expected_output = make_log_line('test_literal_string', 60, None, 'testing') assert actual_output == expected_output
def test_vars(var, capfd): log(var) actual_output = capfd.readouterr().out expected_output = make_log_line('test_vars', 53, 'var', var) assert actual_output == expected_output