0
0
PyTesttesting~10 mins

Test packages 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 pytest in a test file.

PyTest
import [1]
Drag options to blanks, or click blank then click option'
Apytest
Bunittest
Crequests
Dos
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unittest instead of pytest
Importing unrelated modules
2fill in blank
medium

Complete the code to define a test function inside a test package.

PyTest
def [1]():
    assert 1 + 1 == 2
Drag options to blanks, or click blank then click option'
Atest_sum
Bcheck_sum
Csum_test
DsumCheck
Attempts:
3 left
💡 Hint
Common Mistakes
Not starting function name with 'test'
Using camelCase instead of snake_case
3fill in blank
hard

Fix the error in the test package __init__.py to make it a package.

PyTest
# This file makes the directory a package
[1]
Drag options to blanks, or click blank then click option'
A__init__.py
Bdef test(): pass
Cimport pytest
Dpass
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving __init__.py empty
Adding unnecessary code causing errors
4fill in blank
hard

Fill both blanks to create a test package with a test module and a test function.

PyTest
tests/
  __init__.py
  test_math.py

# Inside test_math.py:
def [1]():
    assert 3 * 3 == [2]
Drag options to blanks, or click blank then click option'
Atest_multiplication
B9
Ctest_addition
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Wrong function name not starting with 'test'
Wrong expected value in assertion
5fill in blank
hard

Fill all three blanks to create a test package with a test module, test function, and a failing assertion.

PyTest
tests/
  __init__.py
  test_strings.py

# Inside test_strings.py:
def [1]():
    result = 'hello'.upper()
    assert result == '[2]'
    assert result != '[3]'
Drag options to blanks, or click blank then click option'
Atest_uppercase
BHELLO
Chello
Dtest_lowercase
Attempts:
3 left
💡 Hint
Common Mistakes
Wrong function name
Wrong expected string in assertion
Confusing uppercase and lowercase