COMP 110: Qz04– Complete Questions with 100%
Correct Answers | Verified
The assert keyword should be followed by a boolean expression. This expression should
evaluate to True if the unit of functionality you are testing is working correctly, as
expected. - ✔✔True
When using pytest, a popular unit testing framework, what convention must the file
name of the file containing your test functions follow? - ✔✔Ends with _test.py
When using pytest, what convention must the names of the test functions inside the
test file follow in order to be discovered as test cases? - ✔✔begins with test_
Suppose your test subject(s) (the function(s) you are working on) are contained in a
directory named lessons and a file named subjects.py. Imagine the function you are
working on is named example_function. How would you import the function into your
tests file? - ✔✔from lessons.subjects import example_function
Suppose your test functions are contained in a directory named lessons and a file
named subjects_test.py. How would you run pytest from the terminal? - ✔✔python -
m pytest lessons/subjects_test.py
You should write many individual tests that probe specific, individual use and edge cases
rather than very few complex tests that probe many use/edge cases at the same time. -
✔✔True
The same variable name cannot have different meanings in different contexts within a
single Python program. - ✔✔false
, In an environment diagram, a function call frame is its own context for the names of
parameters and variables defined within the function. - ✔✔True
What would be the printed result of evaluating the following Python code listing?
x: int = 0
def f() -> None:
x: int = 1
f()
print (x) - ✔✔0
In an environment diagram for the example above, the function call to f results in a new
frame. That call's evaluation would result in the frame having a variable named x
defined in it whose value is 1. - ✔✔True
The following subquestions regard the code listing below:
x: int = 1
def f(y: int) -> int:
return x + y
print(f(x+1))
Correct Answers | Verified
The assert keyword should be followed by a boolean expression. This expression should
evaluate to True if the unit of functionality you are testing is working correctly, as
expected. - ✔✔True
When using pytest, a popular unit testing framework, what convention must the file
name of the file containing your test functions follow? - ✔✔Ends with _test.py
When using pytest, what convention must the names of the test functions inside the
test file follow in order to be discovered as test cases? - ✔✔begins with test_
Suppose your test subject(s) (the function(s) you are working on) are contained in a
directory named lessons and a file named subjects.py. Imagine the function you are
working on is named example_function. How would you import the function into your
tests file? - ✔✔from lessons.subjects import example_function
Suppose your test functions are contained in a directory named lessons and a file
named subjects_test.py. How would you run pytest from the terminal? - ✔✔python -
m pytest lessons/subjects_test.py
You should write many individual tests that probe specific, individual use and edge cases
rather than very few complex tests that probe many use/edge cases at the same time. -
✔✔True
The same variable name cannot have different meanings in different contexts within a
single Python program. - ✔✔false
, In an environment diagram, a function call frame is its own context for the names of
parameters and variables defined within the function. - ✔✔True
What would be the printed result of evaluating the following Python code listing?
x: int = 0
def f() -> None:
x: int = 1
f()
print (x) - ✔✔0
In an environment diagram for the example above, the function call to f results in a new
frame. That call's evaluation would result in the frame having a variable named x
defined in it whose value is 1. - ✔✔True
The following subquestions regard the code listing below:
x: int = 1
def f(y: int) -> int:
return x + y
print(f(x+1))