what causes TypeError?
TypeError happens when an object (everything in Python is an object) is used in a way that it should not be.
preview
I have these tests by the end of the chapter
1def function_00(the_input):
2 return None
3
4
5def function_01(first, second):
6 return None
7
8
9def function_02(first, second, third):
10 return None
11
12
13def function_03(first, second, third, fourth):
14 return None
17def function_04(argument):
18 return None
19
20
21def function_05(argument_0, argument_1):
22 return None
23
24
25def function_06(
26 argument_0, argument_1,
27 argument_2,
28):
29 return None
30
31
32def function_07(
33 argument_0, argument_1,
34 argument_2, argument_n,
35):
36 return None
39def function_08(name, argument):
40 return None
41
42
43def test_type_error_w_positional_arguments():
44 function_00('a')
45 function_01('a', 'b')
46 function_02('a', 'b', 'c')
47 function_03('a', 'b', 'c', 'd')
48 function_04('a')
49 function_05('a', 'b')
50 function_06('a', 'b', 'c')
51 function_07('a', 'b', 'c', 'd')
52 function_08('last', 'one')
55def test_type_error_w_keyword_arguments():
56 function_00(the_input=0)
57 function_01(
58 first='first',
59 second={'key': 'value'},
60 )
61 function_02(
62 third=(0, 1, 2, 'n'),
63 second=[0, 1, 2, 'n'],
64 first={0, 1, 2, 'n'},
65 )
66 function_03(
67 first=None,
68 second=False,
69 third=True,
70 fourth=4,
71 )
72 function_04(argument='value')
73 function_05(
74 argument_0='value_1',
75 argument_1=(0, 1, 2, 'n'),
76 )
77 function_06(
78 argument_0='value_1',
79 argument_1=(0, 1, 2, 'n'),
80 argument_2=[0, 1, 2, 'n'],
81 )
82 function_07(
83 argument_0=(0, 1, 2, 'n'),
84 argument_1=[0, 1, 2, 'n'],
85 argument_2={0, 1, 2, 'n'},
86 argument_n={'key': 'value'},
87 )
88 function_08(
89 argument='positional',
90 name='keyword',
91 )
94def test_type_error_w_args_and_kwargs():
95 function_00('argument')
96 function_01(1, 0)
97 function_02(
98 third=True, second=False,
99 first=None,
100 )
101 function_03(
102 second=[0, 1, 2, 'n'],
103 first=(0, 1, 2, 'n'),
104 third={0, 1, 2, 'n'},
105 fourth={'key': 'value'},
106 )
107 function_04(argument='value_2')
108 function_05((0, 1, 2, 'n'), [0, 1, 2, 'n'])
109 function_06(
110 argument_2=(0, 1, 2, 'n'),
111 argument_0=[0, 1, 2, 'n'],
112 argument_1={0, 1, 2, 'n'},
113 )
114 function_07(
115 argument_n={'key': 'value'},
116 argument_2={0, 1, 2, 'n'},
117 argument_0=(0, 1, 2, 'n'),
118 argument_1=[0, 1, 2, 'n'],
119 )
120 function_08(
121 'positional',
122 argument='keyword',
123 )
124
125
126# Exceptions seen
127# AssertionError
128# NameError
129# TypeError
questions about TypeError
start the project
I name this project
type_errorI open a terminal
I change directory to the
type_errorfolder in thepumping_pythonfolderthe terminal shows
cd: no such file or directory: type_errorI use uv to make a directory for the project and initialize it
the terminal shows
Initialized project `type-error` at `../pumping_python/type_error`then goes back to the command line.
I change directory to the project
the terminal shows I am in the
type_errorfolder.../pumping_python/type_errorI make a directory for the tests
the terminal goes back to the command line.
I make the
testsdirectory a Python packageDanger
use 2 underscores (__) before and after
initfor__init__.pynot_init_.pytouch tests/__init__.pyNew-Item tests/__init__.pythe terminal goes back to the command line.
I make an empty file for the tests in the
testsfoldertouch tests/test_type_error.pyNew-Item tests/test_type_error.pythe terminal goes back to the command line.
I open
test_type_error.pyI add the first failing test to
test_type_error.py1def test_failure(): 2 assert False is TrueI go back to the terminal
I use echo to add pytest to
requirements.txtecho "pytest" > requirements.txtI add pytest-watcher to the requirements file
echo "pytest-watcher" >> requirements.txtthe terminal goes back to the command line.
I use Out-File to add pytest to
requirements.txt"pytest" | Out-File requirements.txt -Encoding UTF8I add pytest-watcher to the requirements file
"pytest-watcher" >> requirements.txt
I use uv to install pytest-watcher with the requirements file
the terminal shows that it installed pytest-watcher and its dependencies.
I add the new files and folder to git for tracking
the terminal goes back to the command line.
I add a git commit message
the terminal shows a summary of the changes then goes back to the command line.
I use pytest-watcher to run the tests automatically
the terminal is my friend, and shows AssertionError
========================== ERRORS ========================== ______ ERROR collecting tests/test_type_error.py ______ tests/test_type_error.py:2: in <module> assert False is True E assert False is True ================= short test summary info ================== ERROR tests/test_type_error.py - assert False is True !!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!! ===================== 1 error in L.MNs =====================if the terminal does not show the same error, then check if
your
tests/__init__.pyhas two underscores (__) before and afterinitfor__init__.pynot_init_.pyyou ran
echo "pytest-watcher" >> requirements.txt, to addpytest-watcherto the requirements file
and try
uv run pytest-watcher . --now --patterns "**/*.py"againI add AssertionError to the list of Exceptions seen, in
test_type_error.py1def test_failure(): 2 assert False is True 3 4 5# Exceptions seen 6# AssertionErrorI change False to True in the assertion
1def test_failure(): 2 # assert False is True 3 assert True is True 4 5 6# Exceptions seen 7# AssertionErrorthe test passes.
test_type_error_w_positional_arguments
TypeError happens when I call a function in a way that is different from its signature. I have to match the number of arguments in the function definition when I call the function with positional arguments.
RED: make it fail
I change
test_failureto test_type_error_w_positional_arguments1def test_type_error_w_positional_arguments(): 2 function_00('a') 3 4 5# Exceptions seen 6# AssertionErrorthe terminal is my friend, and shows NameError
NameError: name 'function_00' is not definedbecause there is nothing named
function_00intest_type_error.py.I add NameError to the list of Exceptions seen
GREEN: make it pass
I add a definition for the function
1def test_type_error_w_positional_arguments(): 2 def function_00(): 3 return None 4 5 function_00('a') 6 7 8# Exceptions seenthe terminal is my friend, and shows TypeError
TypeError: test_type_error_w_positional_arguments .<locals>.function_00() takes 0 positional arguments but 1 was givenbecause
the call to
function_00which belongs to test_type_error_w_positional_arguments used one input ('a').the function definition (signature) of
function_00does not allow any inputs when it is called since the parentheses are empty.the call to a function must match its signature (definition).
I add TypeError to the list of Exceptions seen
I add a name in parentheses to the function definition
1def test_type_error_w_positional_arguments(): 2 # def function_00(): 3 def function_00(the_input): 4 return None 5 6 function_00('a') 7 8 9# Exceptions seenthe test passes because the call to the function matches its definition.
REFACTOR: make it better
I add a call to
function_011def test_type_error_w_positional_arguments(): 2 # def function_00(): 3 def function_00(the_input): 4 return None 5 6 function_00('a') 7 8 function_01('a', 'b') 9 10 11# Exceptions seenthe terminal is my friend, and shows NameError
NameError: name 'function_01' is not definedbecause there is nothing named
function_01intest_type_error.py.I add a definition for
function_01the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_positional_arguments .<locals>.function_01() takes 1 positional argument but 2 were givenbecause
the call to
function_01which belongs to test_type_error_w_positional_arguments uses two positional_arguments ('a'and'b').the function definition (signature) of
function_01only allows one input.the call to a function must match its signature (definition).
I change the name of the first input, then add another name in parentheses so that the call to the function and its definition match
the test passes because the call to the function matches its definition.
I add a call to
function_02the terminal is my friend, and shows NameError
NameError: name 'function_02' is not definedbecause there is nothing named
function_02intest_type_error.py.I add a definition for
function_02the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_positional_arguments .<locals>.function_02() takes 2 positional arguments but 3 were givenbecause
the call to
function_02which belongs to test_type_error_w_positional_arguments uses three positional arguments ('a','b'and'c').the function definition (signature) of
function_02only allows two inputs.the call to a function must match its signature (definition).
I add a third name in parentheses so that the call to
function_02and its definition matchthe test passes because the call to the function matches its definition.
I add a call to
function_03the terminal is my friend, and shows NameError
NameError: name 'function_03' is not definedbecause there is nothing named
function_03intest_type_error.py.I add a definition for
function_03the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_positional_arguments .<locals>.function_03() takes 3 positional arguments but 4 were givenbecause
the call to
function_03which belongs to test_type_error_w_positional_arguments uses four positional arguments ('a','b','c','d').the function definition (signature) of
function_03only allows three inputs.the call to a function must match its signature (definition).
I add a fourth name in parentheses so that the call to
function_03and its definition matchthe test passes because the call to the function matches its definition.
I remove the commented lines from test_type_error_w_positional_arguments
1def test_type_error_w_positional_arguments(): 2 def function_00(the_input): 3 return None 4 5 function_00('a')I open a new terminal then change directories to
type_errorI add a git commit message in the new terminal
the terminal shows a summary of the changes then goes back to the command line.
I have to call a function with the same number of inputs that are in its definition.
test_type_error_w_keyword_arguments
TypeError happens when I call a function in a way that is different from its signature. I have to match the names of arguments in the function definition when I call the function with keyword arguments.
RED: make it fail
I go back to the terminal where the tests are running
I add a test with a call to
function_04with a keyword argumentthe terminal is my friend, and shows NameError
NameError: name 'function_04' is not definedbecause there is nothing named
function_04intest_type_error.py.
GREEN: make it pass
I add a definition for
function_04the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_keyword_arguments .<locals>.function_04() got an unexpected keyword argument 'argument'because
the call to
function_04which belongs to test_type_error_w_keyword_arguments uses a keyword argument (argument='value').the function definition (signature) of
function_04does not allow any inputs since the parentheses are empty.the call uses a name (
argument) that is not in the parentheses of its definition.the call to a function must match its signature (definition).
I add
argumentin the parentheses so that the call tofunction_04and its definition matchthe test passes because the call to the function matches its definition.
REFACTOR: make it better
I add a call to
function_05with keyword argumentsthe terminal is my friend, and shows NameError
NameError: name 'function_05' is not definedI add a definition for
function_05the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_keyword_arguments .<locals>.function_05() got an unexpected keyword argument 'argument_0'. Did you mean 'argument'?because
the call to
function_05which belongs to test_type_error_w_keyword_arguments uses keyword arguments (argument_0='value_1'andargument_1=(0, 1, 2, 'n')).the function definition (signature) of
function_05only allows one input, with the nameargument.the call uses a name (
argument_0) that is not in the parentheses of its definition.the call to a function must match its signature (definition).
I change the name of the input in the definition to match the call
TypeError: test_type_error_w_keyword_arguments .<locals>.function_05() got an unexpected keyword argument 'argument_1'. Did you mean 'argument_0'?because the call uses a name (
argument_1) that is not in the parentheses of its definition.I add
argument_1to the parentheses so that the call tofunction_05and its definition matchthe test passes because the call to the function matches its definition.
I add a call to
function_06with keyword argumentsthe terminal is my friend, and shows NameError
NameError: name 'function_06' is not definedI add a definition for
function_06the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_keyword_arguments .<locals>.function_06() got an unexpected keyword argument 'argument_2'. Did you mean 'argument_0'?because
the call to
function_06which belongs to test_type_error_w_keyword_arguments uses keyword arguments (argument_0='value_1',argument_1=(0, 1, 2, 'n')andargument_2=[0, 1, 2, 'n']).the function definition (signature) of
function_06only allows two inputs.the call uses a name (
argument_2) that is not in the parentheses of its definition.the call to a function must match its signature (definition).
I add
argument_2to the parentheses so that the call tofunction_06and its definition matchthe test passes because the call to the function matches its definition.
I add a call to
function_07with keyword argumentsthe terminal is my friend, and shows NameError
NameError: name 'function_07' is not definedI add a definition for
function_07the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_keyword_arguments .<locals>.function_07() got an unexpected keyword argument 'argument_n'. Did you mean 'argument_0'?because
the call to
function_07which belongs to test_type_error_w_keyword_arguments uses keyword arguments (argument_0=(0, 1, 2, 'n'),argument_1=[0, 1, 2, 'n'],argument_2={0, 1, 2, 'n'}andargument_n={'key': 'value'}).the function definition (signature) of
function_07only allows three inputs.the call uses a name (
argument_n) that is not in the parentheses of its definition.the call to a function must match its signature (definition).
I add
argument_nto the parentheses so that the call tofunction_07and its definition matchthe test passes because the call to the function matches its definition.
I remove the commented lines from test_type_error_w_keyword_arguments
I add a git commit message in the other terminal
the terminal shows a summary of the changes then goes back to the command line.
If I call a function with keyword arguments, I have to use the same names that are in its definition.
test_type_error_w_args_and_kwargs
TypeError happens when I call a function in a way that is different from its signature. I cannot give two values for the same argument in the function definition when I call a function.
RED: make it fail
I go back to the terminal where the tests are running
I add a test with a call to
function_08with a positional and keyword argumentthe terminal is my friend, and shows NameError
NameError: name 'function_08' is not definedbecause there is no definition for
function_08in the file.
GREEN: make it pass
I add a function definition for
function_08the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_args_and_kwargs .<locals>.function_08() got multiple values for argument 'argument'because
the call to
function_08which belongs to test_type_error_w_args_and_kwargs uses positional and keyword arguments ('positional'andargument='keyword').the function definition (signature) of
function_08takes one argument (argument). How does Python know which value to use forargumentif I use the position and the name?the call to a function must match its signature (definition).
I add another name to the parentheses
the terminal still shows TypeError because the call gives
'positional'as the value for the first argument which isargumentin the definition, and it gives'keyword'as the value forargumentas a keyword argument.I change the order of the names in the parentheses of the function definition
the test passes because the call to the function matches its definition.
REFACTOR: make it better
I add another call to
function_08the terminal is my friend, and shows TypeError
TypeError: test_type_error_w_args_and_kwargs .<locals>.function_08() got multiple values for argument 'name'because
the call to
function_08which belongs to test_type_error_w_args_and_kwargs uses'positional'as the value for the first argument which isnamein the definition, and uses'keyword'as the value fornameas a keyword argument.the function definition (signature) of
function_08takes two arguments (nameandargument). How does Python know which value to use fornameif I use the position and the name?
I use keyword arguments to make the call clearer
the test passes because the call to the function matches its definition.
I add a call to
function_01with a positional and keyword argumentthe terminal is my friend, and shows NameError
NameError: name 'function_01' is not definedbecause
function_01belongs to the test_type_error_w_positional_arguments function and I cannot reach it from outside test_type_error_w_positional_arguments.I move
function_01out of test_type_error_w_positional_arguments so that it can be called from anywhere in the file1def function_01(first, second): 2 return None 3 4 5def test_type_error_w_positional_arguments(): 6 def function_00(the_input): 7 return None 8 9 function_00('a') 10 function_01('a', 'b') 11 12 def function_02(first, second, third):the terminal is my friend, and shows TypeError
TypeError: function_01() got multiple values for argument 'first'because the call to
function_01from test_type_error_w_args_and_kwargs uses1as the value for the first argument which isfirstin the definition, and uses0as the value forfirstas a keyword argument.I change the call from test_type_error_w_args_and_kwargs to only use positional arguments to make it clearer
the test passes because the call to the function matches its definition.
I add a call to
function_02with arguments that are not clearthe terminal is my friend, and shows NameError
NameError: name 'function_02' is not definedbecause
function_02belongs to the test_type_error_w_positional_arguments function and I cannot reach it from outside test_type_error_w_positional_arguments.I move
function_02out of test_type_error_w_positional_arguments so that it can be called from anywhere in the file1def function_01(first, second): 2 return None 3 4 5def function_02(first, second, third): 6 return Nonethe terminal is my friend, and shows TypeError
TypeError: function_02() got multiple values for argument 'first'because the call to
function_02from test_type_error_w_args_and_kwargs usesFalseas the first positional argument which is namedfirstin the definition, and usesNoneas the value forfirstas a keyword argument.I change the first value in the call from test_type_error_w_args_and_kwargs to a keyword argument to make it clearer
the terminal is my friend, and shows TypeError
TypeError: function_02() missing 1 required positional argument: 'third'because
the call to
function_02from test_type_error_w_args_and_kwargs uses two arguments.the function definition (signature) of
function_02takes three arguments (first,secondandthird).
I add a third argument to the call
the terminal is my friend, and shows TypeError
TypeError: function_02() got multiple values for argument 'first'because the call to
function_02from test_type_error_w_args_and_kwargs usesTrueas the first positional argument which is namedfirstin the definition, and usesNoneas the value forfirstas a keyword argument.I change the call from test_type_error_w_args_and_kwargs to use a keyword argument for
True, to make it clearerthe test passes because the call to the function matches its definition.
I add a call to
function_03the terminal is my friend, and shows NameError
NameError: name 'function_03' is not definedbecause
function_03belongs to the test_type_error_w_positional_arguments function and I cannot reach it from outside test_type_error_w_positional_arguments.I move
function_03out of test_type_error_w_positional_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_03() got multiple values for argument 'first'because the call uses an argument in the first position and uses a keyword argument with the same name as the argument in the first position.
I add a keyword argument for the first value in the call to
function_03from test_type_error_w_args_and_kwargs to make it clearerthe test passes because the call to the function matches its definition.
I add a call to
function_07from test_type_error_w_args_and_kwargsthe terminal is my friend, and shows NameError
NameError: name 'function_07' is not definedbecause
function_07belongs to the test_type_error_w_keyword_arguments function and I cannot reach it from outside test_type_error_w_keyword_arguments.I move
function_07out of test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_07() got multiple values for argument 'argument_0'because
the call to
function_07from test_type_error_w_args_and_kwargs uses an argument in the first position and uses a keyword argument with the same name as the argument in the first position.the function definition (signature) of
function_07takes four arguments. How does Python know which value to use forargument_0if I use both the position and the name of the argument for two values?the call to a function must match its signature (definition).
I change the call to use a keyword argument, then change its position
the terminal still shows TypeError because the call uses an argument in the first position and uses a keyword argument with the same name as the argument in the first position.
I use a keyword argument to make it clearer
the test passes because the call to the function matches its definition.
I add a call to
function_00from test_type_error_w_args_and_kwargsthe terminal is my friend, and shows NameError
NameError: name 'function_00' is not definedbecause
function_00belongs to the test_type_error_w_positional_arguments function and I cannot reach it from outside test_type_error_w_positional_arguments.I move
function_00out of test_type_error_w_positional_arguments1def function_00(the_input): 2 return None 3 4 5def function_01(first, second): 6 return Nonethe terminal is my friend, and shows TypeError
TypeError: function_00() got multiple values for argument 'the_input'because
the call to
function_00from test_type_error_w_args_and_kwargs uses an argument in the first position and uses a keyword argument with the same name as the argument in the first position.the function definition (signature) of
function_00takes one argument. How does Python know which value to use forthe_inputif I use both the position and the name of the argument?the call to a function must match its signature (definition).
I change the call to
function_00from test_type_error_w_args_and_kwargs to match the signaturethe test passes because the call to the function matches its definition.
I add a call to
function_04from test_type_error_w_args_and_kwargsthe terminal is my friend, and shows NameError
NameError: name 'function_04' is not definedbecause
function_04belongs to the test_type_error_w_keyword_arguments function and I cannot reach it from outside test_type_error_w_keyword_arguments.I move
function_04out of test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_04() got multiple values for argument 'argument'because
the call to
function_04from test_type_error_w_args_and_kwargs uses an argument in the first position and uses a keyword argument with the same name as the argument in the first position.the function definition (signature) of
function_04takes one argument. How does Python know which value to use forargumentif I use both the position and the name of the argument?the call to a function must match its signature (definition).
I change the call to
function_04from test_type_error_w_args_and_kwargs to match the signaturethe test passes because the call to the function matches its definition.
I add a call to
function_05from test_type_error_w_args_and_kwargsthe terminal is my friend, and shows NameError
NameError: name 'function_05' is not definedI move
function_05out of test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_05() got multiple values for argument 'argument_0'because …
I change the call to
function_05from test_type_error_w_args_and_kwargs to make it match the signaturethe test passes because the call to the function matches its definition.
I add a call to
function_06from test_type_error_w_args_and_kwargsthe terminal is my friend, and shows NameError
NameError: name 'function_06' is not definedbecause
function_06belongs to the test_type_error_w_keyword_arguments function.I move
function_06out of test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_06() got multiple values for argument 'argument_1'I use another keyword argument in the call to
function_06from test_type_error_w_args_and_kwargsthe terminal is my friend, and shows TypeError
TypeError: function_06() got multiple values for argument 'argument_0'I use one more keyword argument to make it clearer
the test passes because the call to the function matches its definition.
I remove the commented lines from test_type_error_w_args_and_kwargs
test TypeError with required and unexpected arguments
RED: make it fail
I go back to the terminal where the tests are running
I add a call to
function_03from test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_03() missing 1 required positional argument: 'fourth'because the signature only allows calls with four inputs, and it got called with three.
GREEN: make it pass
I add fourth with a value to the call
46def test_type_error_w_keyword_arguments():
47 function_03(
48 first=None,
49 second=False,
50 third=True,
51 fourth=4,
52 )
53 function_04(argument='value')
the test passes because the call to the function matches its definition.
REFACTOR: make it better
I add a call to
function_02from test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_02() got an unexpected keyword argument 'fourth'because the call uses a name (
fourth) that is not in the parentheses of its definition.I remove the unexpected keyword argument from the call
the test passes because the call to the function matches its definition.
I add a call to
function_01from test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_01() missing 1 required positional argument: 'first'because the signature only allows calls with two inputs, and it got called with one.
I change the call to match the signature
the test passes because the call to the function matches its definition.
I add a call to
function_00from test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_00() got an unexpected keyword argument 'second'I remove
secondfrom the call from test_type_error_w_keyword_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_00() got an unexpected keyword argument 'first'because the call …
I remove
firstfrom the callthe terminal is my friend, and shows TypeError
TypeError: function_00() missing 1 required positional argument: 'the_input'-
the test passes because I used the same name in the definition of the function when I called it with keyword arguments.
I move the call to
function_08from test_type_error_w_args_and_kwargs that uses keyword arguments to test_type_error_w_keyword_argumentsthe terminal is my friend, and shows NameError
NameError: name 'function_08' is not definedI move
function_08out of test_type_error_w_args_and_kwargsthe test is green again.
I remove the commented lines from test_type_error_w_keyword_arguments
I add a call to
function_04from test_type_error_w_positional_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_04() missing 1 required positional argument: 'argument'I add a value to the call to
function_04the test passes because the call to the function matches its definition.
I add a call to
function_05from test_type_error_w_positional_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_05() takes 2 positional arguments but 3 were givenI remove a value from the call to
function_05the test passes because the call to the function matches its definition.
I add a call to
function_06from test_type_error_w_positional_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_06() missing 1 required positional argument: 'argument_2'I add a value to the call to
function_06the test passes because the call to the function matches its definition.
I add a call to
function_07from test_type_error_w_positional_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_07() takes 4 positional arguments but 5 were givenI remove a value from the call to
function_07the test passes because the call to the function matches its definition.
I add a call to
function_08from test_type_error_w_positional_argumentsthe terminal is my friend, and shows TypeError
TypeError: function_08() missing 1 required positional argument: 'argument'I add a value to the call to
function_08the test passes because the call to the function matches its definition.
I remove the commented lines from test_type_error_w_positional_arguments
I add a git commit message in the other terminal
git commit --all --message \ 'test with required and unexpected arguments'
I have to call a function with the same number or names of arguments that are in its definition.
close the project
I close
test_type_error.pyI click in the terminal where the tests are running
I use q on the keyboard to leave the tests. The terminal goes back to the command line.
I change directory to the parent of
type_errorthe terminal shows
.../pumping_pythonI am back in the
pumping_pythondirectory.
review
I ran tests for TypeError with
My problem with the tests is that they all show the correct way to call the functions I made in the file. If someone reads the file or runs it, there is no way for them to know how any of the calls are related to TypeError unless they go through the process with me, there has to be a better way.
code from the chapter
what is next?
Would you like to test AssertionError with functions that take input?
rate pumping python
If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too.