Bird
0
0

Given the following test module test_sample.py with these functions:

medium📝 Predict Output Q13 of 15
PyTest - Test Organization
Given the following test module test_sample.py with these functions:
def test_add():
    assert 1 + 1 == 2

def add():
    return 1 + 1

def test_subtract():
    assert 2 - 1 == 1

Which functions will pytest run as tests?
AAll three functions
BOnly <code>add</code>
C<code>test_add</code> and <code>test_subtract</code>
DOnly <code>test_add</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify pytest test function naming

    pytest runs functions starting with test_ automatically as tests.
  2. Step 2: Check each function name

    test_add and test_subtract start with test_, so pytest runs them. add does not start with test_, so it is ignored.
  3. Final Answer:

    test_add and test_subtract -> Option C
  4. Quick Check:

    Functions starting with test_ run as tests [OK]
Quick Trick: Only functions starting with test_ run as tests [OK]
Common Mistakes:
MISTAKES
  • Thinking all functions in test file run as tests
  • Confusing helper functions with test functions
  • Ignoring function name prefixes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes