FlashKeepers

Python · Python · College and University

Python Testing with Pytest Basics

Writing test functions, fixtures, and assertions with the pytest framework, each explained with a short example.

About this set

30 basic cards for Python Python. It opens with "In pytest, what must a test function name start with?" and "What should pytest test files be named?". More College and University decks are listed below.

30 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

In pytest, what must a test function name start with?
Show answertest_
What should pytest test files be named?
Show answertest_*.py or *_test.py
What is the basic syntax for an assertion in pytest?
Show answerassert condition
How do you assert that two values are equal in pytest?
Show answerassert value1 == value2
How do you test that a function raises an exception in pytest?
Show answerwith pytest.raises(ExceptionType):
What is a pytest fixture?
Show answerA function that provides test data or setup/teardown logic for tests
What decorator marks a function as a pytest fixture?
Show answer@pytest.fixture
How do you use a fixture in a test function?
Show answerPass the fixture name as a parameter to the test function
What is the default scope of a pytest fixture?
Show answerfunction
What does scope='class' mean for a pytest fixture?
Show answerThe fixture is created once per test class and reused across all methods in that class
What does scope='module' mean for a pytest fixture?
Show answerThe fixture is created once per module and reused across all tests in that module
What does scope='session' mean for a pytest fixture?
Show answerThe fixture is created once per test session and reused across all tests
How do you add setup code to a fixture?
Show answerPlace code before the yield statement
How do you add cleanup code to a fixture?
Show answerPlace code after the yield statement
What is conftest.py in pytest?
Show answerA special file where shared fixtures and configuration for a directory and subdirectories are defined

15 more cards in the app

Study this set free