0
0
PyTesttesting~10 mins

Test modules 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 import the pytest module correctly.

PyTest
import [1]
Drag options to blanks, or click blank then click option'
Atesting
Bpytest
Ctest
Dunittest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'test' or 'testing' instead of 'pytest' as the module name.
Trying to import 'unittest' when the task is about pytest.
2fill in blank
medium

Complete the code to define a simple test function using pytest.

PyTest
def [1]():
    assert 1 + 1 == 2
Drag options to blanks, or click blank then click option'
Acheck_add
Baddition_test
Ctest_addition
Dverify
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the function without the 'test_' prefix so pytest does not find it.
Using generic names that do not start with 'test_'.
3fill in blank
hard

Fix the error in the test function name so pytest can discover it.

PyTest
def [1]():
    assert 'hello'.upper() == 'HELLO'
Drag options to blanks, or click blank then click option'
Atest_hello
Bhello_test
Ccheck_hello
DhelloCheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using names like 'hello_test' which do not start with 'test_'.
Using camelCase or other naming styles that do not start with 'test_'.
4fill in blank
hard

Fill both blanks to create a test module with two test functions using pytest.

PyTest
import pytest

def [1]():
    assert 3 * 3 == 9

def [2]():
    assert 'abc'.capitalize() == 'Abc'
Drag options to blanks, or click blank then click option'
Atest_multiplication
Bmultiply_test
Ctest_capitalize
Dcapitalize_test
Attempts:
3 left
💡 Hint
Common Mistakes
Naming functions without the 'test_' prefix.
Using inconsistent naming styles.
5fill in blank
hard

Fill all three blanks to write a pytest test module that imports pytest, defines a test function, and uses an assertion.

PyTest
import [1]

def [2]():
    result = 5 + 5
    assert result [3] 10
Drag options to blanks, or click blank then click option'
Apytest
Btest_sum
C==
Dunittest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'unittest' instead of 'pytest'.
Naming the test function without 'test_' prefix.
Using wrong comparison operators in assertions.