pytest — Testing Like a Professional — Concept Check
Questions on pytest — Testing Like a Professional. pytest turns plain assert into a test framework: test_ functions, parametrize for tables of cases, fixtures for setup/teardown, and raises for exception paths.
Questions in this quiz
8 questions on pytest — Testing Like a Professional — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You are testing a function that should raise an exception for invalid input. Which pytest feature allows you to verify this behavior?
- Apytest.fixture
- Bpytest.raises
- Cpytest.mark.parametrize
- Dpytest.asserts
2.A test function is failing, and pytest shows 'AssertionError: assert 900.0 == 901'. What does this indicate?
- AThe test file is not in the correct directory
- BThe expected result was incorrect
- CThe test function was not named correctly
- Dpytest is not installed properly
3.You need to run the same test with multiple sets of inputs. Which pytest feature should you use?
- Apytest.fixture
- Bpytest.raises
- Cpytest.mark.parametrize
- Dpytest.assert
4.A test requires a temporary database setup and teardown. Which pytest feature helps with this?
- AParametrize
- BRaises
- CFixtures
- DAssertions
5.You have a test file named 'calculator_tests.py'. Why might pytest not discover it?
- AThe file is not in the root directory
- BThe file name does not follow the 'test_*.py' convention
- CThe assert statements are missing
- DThe test functions are not defined inside classes
6.What happens if a test function using a fixture does not explicitly call the fixture?
- AThe fixture must be called manually
- BThe fixture is automatically injected by name
- CThe test will fail
- DThe test will be skipped
7.You want to test a function that applies a discount to a price. Which pytest feature allows you to test multiple discount scenarios efficiently?
- Apytest.assert
- Bpytest.fixture
- Cpytest.mark.parametrize
- Dpytest.raises
8.A test function using pytest.raises is not failing even when an error is expected. What could be the issue?
- AThe error is not being raised in the code
- Bpytest.raises is not used correctly
- CThe test function is not named correctly
- DThe test file is not in the correct directory