Bird
0
0

You want to test a function multiply(a, b) that returns the product of two numbers. Which PyTest test function correctly tests that multiply(3, 4) returns 12?

hard🚀 Application Q15 of 15
PyTest - Basics and Setup
You want to test a function multiply(a, b) that returns the product of two numbers. Which PyTest test function correctly tests that multiply(3, 4) returns 12?
Adef test_multiply():\n assert multiply(3, 4) == 7
Bdef test_multiply():\n assert multiply(3, 4) = 12
Cdef multiply_test():\n assert multiply(3, 4) == 12
Ddef test_multiply():\n assert multiply(3, 4) == 12
Step-by-Step Solution
Solution:
  1. Step 1: Verify test function name

    The function name must start with test_, so test_multiply is correct.
  2. Step 2: Check assertion correctness

    The assertion must compare with == and the expected result is 12, so assert multiply(3, 4) == 12 is correct.
  3. Final Answer:

    def test_multiply():\n assert multiply(3, 4) == 12 -> Option D
  4. Quick Check:

    Correct name and assert with == 12 = def test_multiply():\n assert multiply(3, 4) == 12 [OK]
Quick Trick: Test functions start with test_ and assert expected == actual [OK]
Common Mistakes:
MISTAKES
  • Wrong expected value in assert
  • Wrong function name prefix
  • Using = instead of == in assert

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes