D. The test checks two different features in one function
Solution
Step 1: Review test actions
The test checks login and profile update in the same function, two separate features.
Step 2: Understand single responsibility principle
Each test should check only one behavior to keep tests clear and focused.
Final Answer:
The test checks two different features in one function -> Option D
Quick Check:
Multiple features in one test = violation [OK]
Hint: One test, one feature; multiple features break single responsibility [OK]
Common Mistakes:
Ignoring multiple assertions as multiple responsibilities
Assuming syntax errors cause failure here
Confusing setup with test logic
5. You have a test that checks user registration, login, and logout all in one function. How should you refactor it to follow single responsibility in pytest?
hard
A. Split the test into three separate tests: one for registration, one for login, and one for logout
B. Keep all checks in one test but add comments to separate them
C. Remove login and logout checks and test only registration
D. Combine registration and login in one test, logout in another
Solution
Step 1: Identify responsibilities in the test
The test currently checks three different user actions: registration, login, and logout.
Step 2: Apply single responsibility principle
Each test should focus on one action to improve clarity and maintainability.
Step 3: Refactor approach
Splitting into three tests ensures each test checks only one feature clearly.
Final Answer:
Split the test into three separate tests: one for registration, one for login, and one for logout -> Option A
Quick Check:
One test per feature = better clarity and easier fixes [OK]
Hint: Split combined tests into single-feature tests [OK]
Common Mistakes:
Keeping multiple features in one test with comments