Recall & Review
beginner
What is pytest-django?
pytest-django is a plugin for pytest that makes it easier to test Django applications by providing Django-specific fixtures and helpers.
Click to reveal answer
beginner
How do you enable database access in a pytest-django test?
You add the pytest marker
@pytest.mark.django_db to the test function or use the db fixture to allow database access during the test.Click to reveal answer
beginner
What is the purpose of the
client fixture in pytest-django?The
client fixture provides a Django test client instance that lets you simulate HTTP requests to your Django application in tests.Click to reveal answer
beginner
How can you run only Django tests using pytest-django?
You can run Django tests by simply running
pytest in your project directory. pytest-django automatically discovers Django tests based on your test files and settings.Click to reveal answer
intermediate
What is the benefit of using pytest fixtures in Django testing?
pytest fixtures help set up and tear down test data or state cleanly and reuse code across tests, making tests easier to write and maintain.
Click to reveal answer
Which pytest-django fixture allows you to simulate HTTP requests?
✗ Incorrect
The
client fixture provides a Django test client to simulate HTTP requests.How do you mark a test to use the database in pytest-django?
✗ Incorrect
The correct marker to enable database access is
@pytest.mark.django_db.What command runs Django tests with pytest-django?
✗ Incorrect
Running
pytest in your project runs Django tests when pytest-django is installed.Which of these is NOT a benefit of pytest fixtures in Django testing?
✗ Incorrect
pytest fixtures do not handle database migrations automatically; migrations are managed separately.
What does the
db fixture in pytest-django do?✗ Incorrect
The
db fixture allows tests to access the database.Explain how pytest-django helps in testing Django applications.
Think about what makes Django testing easier with pytest-django.
You got /4 concepts.
Describe the steps to write a simple database test using pytest-django.
Focus on enabling database and writing assertions.
You got /4 concepts.