0
0
PyTesttesting~10 mins

Grouping related tests 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 define a test function using pytest.

PyTest
def test_[1]():
    assert 2 + 2 == 4
Drag options to blanks, or click blank then click option'
Aaddition
Bsum
Ccheck
Dcalculate
Attempts:
3 left
💡 Hint
Common Mistakes
Not starting the function name with 'test_' so pytest won't detect it.
Using vague names that don't describe the test purpose.
2fill in blank
medium

Complete the code to group related tests inside a class using pytest.

PyTest
class TestMathOperations:
    def [1](self):
        assert 3 * 3 == 9
Drag options to blanks, or click blank then click option'
Atest_multiply
Bmultiply
Ccheck_multiply
Dmultiply_test
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting 'test_' prefix in method names inside test classes.
Using method names that don't start with 'test_' so pytest skips them.
3fill in blank
hard

Fix the error in the test class so pytest recognizes the test method.

PyTest
class TestStrings:
    def [1](self):
        assert 'hello'.upper() == 'HELLO'
Drag options to blanks, or click blank then click option'
Auppercase
Buppercase_test
Ccheck_uppercase
Dtest_uppercase
Attempts:
3 left
💡 Hint
Common Mistakes
Naming test methods without 'test_' prefix inside classes.
Using names that pytest does not recognize as tests.
4fill in blank
hard

Fill both blanks to create a test class with two test methods for addition and subtraction.

PyTest
class TestArithmetic:
    def [1](self):
        assert 1 + 1 == 2

    def [2](self):
        assert 5 - 3 == 2
Drag options to blanks, or click blank then click option'
Atest_addition
Badd_test
Ctest_subtraction
Dsubtract_test
Attempts:
3 left
💡 Hint
Common Mistakes
Not using 'test_' prefix for one or both methods.
Using unclear or inconsistent method names.
5fill in blank
hard

Fill all three blanks to create a test class with grouped tests for multiplication, division, and modulus.

PyTest
class TestOperations:
    def [1](self):
        assert 4 * 2 == 8

    def [2](self):
        assert 10 / 2 == 5

    def [3](self):
        assert 10 % 3 == 1
Drag options to blanks, or click blank then click option'
Atest_multiply
Btest_divide
Ctest_modulus
Dmultiply_test
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent naming conventions for test methods.
Forgetting the 'test_' prefix on any method.