Continuous Integration (CI) tools run tests automatically when code changes are made. Which of the following best explains why this helps maintain continuous quality?
Think about how often tests run and when bugs are found.
CI runs tests automatically on every code change, so bugs are found early. This prevents broken code from being merged and keeps quality high continuously.
Given the following pytest test code, what will be the test result when run in a CI pipeline?
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
Check if the function and assertions are logically correct.
The add function correctly sums two numbers. All assertions match expected results, so all tests pass.
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?
page_title = get_page_title() # returns the current page title stringThink about exact match vs partial or presence checks.
To verify the title exactly matches 'Welcome Page', use equality assertion. Other options only check partial or non-empty strings.
Review the pytest test below. It passes locally but fails in CI with a KeyError. Why?
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
Check dictionary keys and what happens when a missing key is accessed.
Accessing a missing key in a dictionary raises KeyError. The test expects 'age' key which is not present, causing failure in CI.
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?
Consider how often the database should reset for test isolation in CI.
Using function scope runs setup and teardown for each test, ensuring clean state and preventing test interference, which is ideal for CI.