4. You added filterwarnings = ignore::DeprecationWarning in pytest.ini but still see deprecation warnings during test runs. What is the likely cause?
medium
A. You need to add --disable-warnings to the command line instead.
B. The filterwarnings option is misspelled or misplaced in the config file.
C. Deprecation warnings cannot be ignored in pytest.
D. Pytest does not support filtering warnings via configuration.
Solution
Step 1: Verify correct spelling and placement of filterwarnings
The option must be spelled exactly as filterwarnings under the [pytest] section in pytest.ini.
Step 2: Understand pytest's support for warning filters
Pytest supports filtering warnings via config. If warnings still appear, likely the option is misspelled or in wrong section.
Final Answer:
The filterwarnings option is misspelled or misplaced in the config file. -> Option B
Quick Check:
Correct spelling and placement = D [OK]
Hint: Check spelling and section for config options [OK]
Common Mistakes:
Assuming pytest ignores config filters
Using wrong option names
Not placing options under [pytest] section
5. You want to ensure all tests marked @pytest.mark.slow are skipped by default unless explicitly included. Which pytest.ini configuration achieves this standardized behavior?
hard
A. [pytest]
markers = slow: marks slow tests
addopts = -m 'not slow'
B. [pytest]
markers = slow: marks slow tests
addopts = -m slow
C. [pytest]
markers = slow: marks slow tests
addopts = --skip slow
D. [pytest]
markers = slow: marks slow tests
addopts = --disable slow
Solution
Step 1: Understand marker usage and addopts filtering
To skip tests marked slow by default, use -m 'not slow' to run tests not marked slow.
Step 2: Identify correct addopts syntax
[pytest]
markers = slow: marks slow tests
addopts = -m 'not slow' uses addopts = -m 'not slow', which tells pytest to exclude slow tests unless overridden.
Final Answer:
[pytest]
markers = slow: marks slow tests
addopts = -m 'not slow' -> Option A
Quick Check:
Exclude slow tests by default = C [OK]
Hint: Use '-m not marker' to skip marked tests by default [OK]
Common Mistakes:
Using '-m slow' runs only slow tests, not skips them
Trying unsupported options like --skip or --disable
Not defining the marker in pytest.ini
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.