← ClaudeAtlas

pytest-oop-patternslisted

OOP-based pytest patterns for API test automation — base classes, service layers, fixtures hierarchy, parametrization, markers, parallel execution, and test isolation.
Izangi2714/claude-code-python-stack · ★ 0 · Testing & QA · score 65
Install: claude install-skill Izangi2714/claude-code-python-stack
# OOP Pytest Patterns for API Testing Strict OOP patterns for building maintainable, scalable pytest test suites. ## When to Activate - Designing test framework architecture - Writing new API test suites - Reviewing test code for OOP compliance - Setting up pytest infrastructure (conftest, fixtures, markers) ## RULE: No Bare Functions Every test MUST be inside a class. This is non-negotiable. ```python # WRONG -- procedural, no encapsulation def test_create_user(): response = httpx.post("/users", json={"email": "a@b.com"}) assert response.status_code == 201 # CORRECT -- OOP, inherits BaseTest, uses service class @allure.feature("User Management") class TestCreateUser(BaseTest): def test_create_user_returns_201(self): data = self.gen.create_user_request() response = self.users_api.create_user(data) assert response.status_code == 201 ``` ## Base Test Class ```python import pytest import allure from framework.clients.http_client import HTTPClient from framework.config.settings import Settings class BaseTest: """Base class for ALL test classes.""" client: HTTPClient settings: Settings @pytest.fixture(autouse=True) def _setup_base(self, http_client: HTTPClient, settings: Settings): """Inject shared dependencies.""" self.client = http_client self.settings = settings class BaseAuthenticatedTest(BaseTest): """Base for tests requiring authentication.""" @pytest.fixture(autouse=True)