0
0
PyTesttesting~20 mins

Why CI integration enables continuous quality in PyTest - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CI Continuous Quality Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does CI integration improve software quality?

Continuous Integration (CI) tools run tests automatically when code changes are made. Which of the following best explains why this helps maintain continuous quality?

ACI delays testing until deployment to production to save time.
BCI replaces manual testing, so testers are no longer needed.
CCI runs tests only after all features are complete, ensuring final quality.
DCI runs tests frequently, catching bugs early and preventing broken code from merging.
Attempts:
2 left
💡 Hint

Think about how often tests run and when bugs are found.

Predict Output
intermediate
2:00remaining
What is the test result when CI runs this pytest test?

Given the following pytest test code, what will be the test result when run in a CI pipeline?

PyTest
def add(a, b):
    return a + b

def test_add():
    assert add(2, 3) == 5
    assert add(-1, 1) == 0
    assert add(0, 0) == 0
AAll tests pass successfully.
BOne test fails due to incorrect assertion.
CSyntaxError occurs because of missing colon.
DTypeError occurs because add function is missing parameters.
Attempts:
2 left
💡 Hint

Check if the function and assertions are logically correct.

assertion
advanced
2:00remaining
Which assertion best verifies a web page title in CI tests?

In a CI test for a web app, you want to check that the page title is exactly 'Welcome Page'. Which pytest assertion is best?

PyTest
page_title = get_page_title()  # returns the current page title string
Aassert 'Welcome' in page_title
Bassert page_title == 'Welcome Page'
Cassert page_title.startswith('Welcome')
Dassert page_title != ''
Attempts:
2 left
💡 Hint

Think about exact match vs partial or presence checks.

🔧 Debug
advanced
2:00remaining
Why does this pytest test fail in CI?

Review the pytest test below. It passes locally but fails in CI with a KeyError. Why?

PyTest
def get_user(data, key):
    return data[key]

def test_get_user():
    user = {'name': 'Alice'}
    assert get_user(user, 'name') == 'Alice'
    assert get_user(user, 'age') == 30
AKeyError occurs because 'age' key is missing in the dictionary.
BSyntaxError due to missing colon in function definition.
CAssertionError because 'age' value is 25, not 30.
DTypeError occurs because get_user expects a list, not dict.
Attempts:
2 left
💡 Hint

Check dictionary keys and what happens when a missing key is accessed.

framework
expert
2:00remaining
Which pytest fixture usage best supports CI continuous testing?

In a CI environment, you want to run tests that need a temporary database setup and teardown for each test. Which pytest fixture usage is best?

A
@pytest.fixture(scope='class')
def temp_db():
    setup_db()
    yield
    teardown_db()
B
@pytest.fixture(scope='session')
def temp_db():
    setup_db()
    yield
    teardown_db()
C
@pytest.fixture(scope='function')
def temp_db():
    setup_db()
    yield
    teardown_db()
D
@pytest.fixture(scope='module')
def temp_db():
    setup_db()
    yield
    teardown_db()
Attempts:
2 left
💡 Hint

Consider how often the database should reset for test isolation in CI.