Chapter Review Questions

Chapter Review Questions#

Note

Source: Python-specific — no direct equivalent in the C# edition. Questions cover pytest conventions, assert usage, and testing strategy.

  1. What naming convention must a test file follow for pytest to discover it automatically?

  2. What naming convention must a test function follow?

  3. What happens when an assert statement fails inside a test function?

  4. Write a test function that verifies abs(-5) == 5.

  5. pytest.raises.

    1. What does pytest.raises(ValueError) do?

    2. When would you use it?

  6. What is the difference between a unit test and an integration test?

  7. Give three examples of edge cases you should always consider when writing tests for a numeric function.

  8. Why is it generally better to have one assertion per test function rather than many?

  9. How do you run only the tests in a file called test_strings.py from the command line?

  10. C# vs. Python testing.

    1. In the C# edition, what attribute marks a test method?

    2. What is the Python pytest equivalent?

    3. What replaces Assert.AreEqual in pytest?