0
0
PyTesttesting~10 mins

Test discovery rules in PyTest - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to name a test function that pytest will discover automatically.

PyTest
def [1]():
    assert 1 + 1 == 2
Drag options to blanks, or click blank then click option'
Atest_addition
Baddition_test
Ccheck_addition
DAddTest
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the function without 'test_' prefix
Using camel case starting with uppercase
2fill in blank
medium

Complete the code to name a test file that pytest will discover automatically.

PyTest
# File name: [1]

def test_example():
    assert True
Drag options to blanks, or click blank then click option'
Aexample_test.py
BTestExample.py
Ctest_example.py
Dexample.py
Attempts:
3 left
💡 Hint
Common Mistakes
Naming file without 'test_' prefix or '_test' suffix
Using uppercase letters in file name
3fill in blank
hard

Fix the error in the test class name so pytest will discover its test methods.

PyTest
class [1]:
    def test_method(self):
        assert True
Drag options to blanks, or click blank then click option'
Amytest
BTestMyClass
CMyTests
DTests
Attempts:
3 left
💡 Hint
Common Mistakes
Class name not starting with 'Test'
Using lowercase class names
4fill in blank
hard

Fill both blanks to create a test function that pytest will discover and run.

PyTest
def [1]([2]):
    assert [2] > 0
Drag options to blanks, or click blank then click option'
Atest_positive
Bvalue
Ccheck_positive
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Function name not starting with 'test_'
Using invalid parameter names
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that filters test data for pytest.

PyTest
filtered = { [1]: [2] for [1] in data if [2] [3] 10 }
Drag options to blanks, or click blank then click option'
Akey
Bvalue
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using same variable name for key and value
Wrong comparison operator