backend / testing / README.md

Pytest Testing Framework

1 min read index source

Pytest Testing Framework

Pytest is a popular Python testing framework that makes it easy to write simple and scalable test cases.

Key Features

Test Discovery

  • Automatically finds test files and functions
  • Naming convention: test_*.py files and test_* functions
  • Supports custom test discovery patterns

Fixtures

  • Reusable test components
  • Dependency injection for tests
  • Scope management (function, class, module, session)
  • Parametrized fixtures

Assertions

  • Rich assertion introspection
  • Detailed failure messages
  • No need for special assertion methods

Common Interview Questions

  1. What are the advantages of pytest over unittest?
  2. Explain pytest fixtures and their scopes
  3. How to parametrize tests in pytest?
  4. What are pytest markers and how to use them?
  5. How to handle test setup and teardown?
  6. Explain pytest plugins and their usage
  7. How to run specific tests or test groups?
  8. What is pytest-xdist and when to use it?
  9. How to mock objects in pytest?
  10. Explain pytest configuration (pytest.ini, conftest.py)
  11. How to generate test coverage reports?
  12. What are pytest hooks and how to use them?