LLM Skills
~/catalog/testing & quality//testing
Testing & qualityGitHub source

Suite de tests flask

/testing

Create, run, and improve tests to validate changes.

davila7davila7
30.6k
May 22, 2026
MIT License
// skill content

Flask Testing Suite Comprehensive testing setup for Flask applications with pytest. ## Usage ``bash # Run all tests pytest # Run with coverage pytest --cov=app --cov-report=html # Run specific test file pytest tests/test_models.py # Run with verbose output pytest -v ` ## Test Configuration `python # pytest.ini [tool:pytest] testpaths = tests python_files = test_*.py python_classes = Test* python_functions = test_* addopts = --cov=app --cov-report=term-missing --cov-report=html:htmlcov --strict-markers --disable-warnings markers = unit: Unit tests integration: Integration tests slow: Slow running tests auth: Authentication tests ` ## Test Fixtures `python # tests/conftest.py import pytest import tempfile import os from app import create_app from app.extensions import db from app.models import User, Post, Category from flask_login import login_user @pytest.fixture(scope='session') def app(): """Create test application.""" # Create temporary database db_fd, db_path = tempfile.mkstemp() app = create_app({ 'TESTING': True, 'SQLALCHEMY_DATABASE_URI': f'sqlite:///{db_path}', 'WTF_CSRF_ENABLED': False, 'SECRET_KEY': 'test-secret-key' }) with app.app_context(): db.create_all() yield app # Cleanup os.close(db_fd) os.unlink(db_path) @pytest.fixture def client(app): """Create test client.""" return app.test_client() @pytest.fixture def runner(app): """Create test CLI runner.""" return app.test_cli_runner() @pytest.fixture def db_session(app): """Create database session for testing.""" with app.app_context(): connection = db.engine.connect() transaction = connection.begin() # Configure session to use the connection db.session.configure(bind=connection) yield db.session # Rollback transaction transaction.rollback() connection.close() db.session.remove() @pytest.fixture def user(db_session): """Create test user.""" user = User( username='testuser', email='test@example.com', first_name='Test', last_name='User' ) user.set_password('testpass123') user.save() return user @pytest.fixture def admin_user(db_session): """Create admin user.""" admin = User( username='admin', email='admin@example.com', first_name='Admin', last_name='User', is_admin=True ) admin.set_password('adminpass123') admin.save() return admin @pytest.fixture def category(db_session): """Create test category.""" category = Category( name='Test Category', description='A test category' ) category.save() return category @pytest.fixture def post(db_session, user, category): """Create test post.""" post = Post( title='Test Post', content='This is a test post content.', slug='test-post', status='published', user_id=user.id, category_id=category.id ) post.save() return post @pytest.fixture def auth_headers(user): """Create authentication headers.""" # For API testing token = user.generate_auth_token() return {'Authorization': f'Bearer {token}'} ` ## Model Testing ``python # tests/testmodels.py import pytest from datetime import datetime from app.models import User, Post, Category from werkzeug.security import checkpasswordhash class TestUser: """Test User model.""" def testusercreation(self, dbsession): """Test user creation.""" user = User( username='newuser', email='new@example.com', firstname='New', lastname='User' ) user.setpassword('password123') user.save() assert user.id is not None assert user.username == 'newuser' assert user.email == 'new@example.com' assert user.fullname == 'New User' assert user.isactive is True assert user.isadmin is False assert user.createdat is not None def testpasswordhashing(self, user): """Test password hashing.""" user.setpassword('newpassword') assert user.passwordhash != 'newpassword' assert checkpasswordhash(user.passwordhash, 'newpassword') assert user.checkpassword('newpassword') assert not user.checkpassword('wrongpassword') def testuserrepr(self, user): """Test user string representation.""" assert repr(user) == '<User testuser>' def testusertodict(self, user): """Test user dictionary conversion.""" userdict = user.todict() assert 'username' in userdict assert 'email' in userdict assert 'passwordhash' not in userdict # Should be excluded def testuser_relationsh

// original public source
davila7/claude-code-templates
/cli-tool/templates/python/examples/flask-app/.claude/commands/testing.md
License: MIT License
Independent project, not affiliated with Anthropic. This skill remains the property of its original author.
// install this skill
Paste this command in your terminal at the root of your project:
mkdir -p .claude/commands && curl -o ".claude/commands/testing.md" "https://raw.githubusercontent.com/davila7/claude-code-templates/main/cli-tool/templates/python/examples/flask-app/.claude/commands/testing.md"
Then in Claude Code, type /testing to activate it.
open_in_newOpen original source
// save
Save available after sign in.
loginSign in to save
// information
Creatordavila7
Stars 30.6k
LicenseMIT License
UpdatedMay 22, 2026
Format.md
AccessFree
// similar

Skills Testing & quality

View allarrow_forward