-
Notifications
You must be signed in to change notification settings - Fork 2
Student Plugins
Every test failure is a learning opportunity. Student plugins transform Mercury from a testing tool into a performance education platform.
Student plugins follow these principles:
- Learn by doing: Understand concepts through real code
- Progressive mastery: Start simple, build complexity
- Immediate feedback: Learn from mistakes instantly
- No shame in learning: Encouraging, not condescending
# First time - creates mercury_config.toml with student profile
mercury-test --profile student
# Subsequent runs automatically use student profile
mercury-test# mercury_config.toml
[mercury]
profile = "student"
[profiles.student]
plugins.enabled = ["discovery", "wizard", "learn", "hints"]
educational_mode = true
show_explanations = true
quiz_difficulty = "beginner"The learn plugin transforms testing into an educational experience:
- Slideshow tutorials: Visual learning with progress tracking
- Interactive quizzes: Test your understanding
- Real-time explanations: Understand what's happening
- Progress tracking: See your improvement over time
# Start general learning mode
mercury-test --learn
# Learn specific topic
mercury-test --learn n1-queries
mercury-test --learn caching
mercury-test --learn indexing
# Quiz mode only
mercury-test --learn --quiz$ mercury-test --learn n1-queries
📚 MERCURY LEARNING MODE
========================
Welcome to: Understanding N+1 Queries
[Slide 1/5] What is an N+1 Query?
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
An N+1 query happens when:
1. You fetch a list of items (1 query)
2. For each item, you fetch related data (N queries)
Example: Getting 100 users and their profiles = 101 queries!
Press ENTER to continue...
[Slide 2/5] Why It's a Problem
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Each database query has overhead:
• Network round trip: ~1ms
• Query parsing: ~0.5ms
• Data transfer: varies
100 users × 2ms = 200ms just in overhead!
Press ENTER to continue...
[Quiz Time!]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Q: You have a view showing 50 blog posts with their authors.
Without optimization, how many queries will Django make?
A) 1 query
B) 2 queries
C) 50 queries
D) 51 queries
Your answer: D
✅ Correct! 1 query for posts + 50 for each author = 51 total
💡 Fix: Use select_related('author') to get everything in 1 query!
- N+1 Queries: Understanding and fixing
- Database Indexing: When and how to index
- Caching Strategies: Memory vs database trade-offs
- Query Optimization: Writing efficient ORM queries
- Memory Management: Understanding Django's memory usage
Perfect for beginners who don't know what to test:
- Interactive menu: Browse available tests
- Smart suggestions: Recommends what to test
- Visual feedback: Colors and icons for clarity
- Pattern learning: Teaches Django test organization
# Start wizard mode
mercury-test --wizard$ mercury-test --wizard
🧙 MERCURY TEST WIZARD
======================
What would you like to test?
1. 📦 All tests (might be slow)
2. 📱 Specific app
3. 📄 Specific test file
4. 🎯 Specific test class
5. 🔧 Specific test method
Your choice: 2
Available apps:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. users (15 tests)
2. products (23 tests)
3. orders (18 tests)
4. api (42 tests)
Select app: 1
Running: python manage.py test users
💡 Tip: You can run this directly next time:
mercury-test users
Provides performance tips based on actual test results:
- Smart timing: Only shows hints when relevant
- Contextual tips: Based on your actual performance
- Progressive learning: Tips get more advanced over time
- Non-intrusive: Configurable thresholds
$ mercury-test
... tests run ...
💡 PERFORMANCE TIP
═════════════════════════════════════
Your tests took 142.3 seconds to complete.
Speed up your tests by running them in parallel:
mercury-test --parallel 4
Where 4 is the number of CPU cores to use.
Most modern computers have 4-8 cores.
To find your core count: python -c "import os; print(os.cpu_count())"
[plugins.hints]
threshold = 30.0 # Show hints after 30 seconds
show_parallel_hint = true
show_specific_test_hint = true
max_hints_per_session = 3In student profile, the discovery plugin provides educational error messages:
$ mercury-test
🔍 Searching for Django project...
├─ Current directory... ❌
├─ Parent directory... ❌
├─ Subdirectories... ❌
└─ ❌ Could not find valid manage.py
⚠️ Found invalid manage.py files:
• /home/user/project/manage.py (missing Django imports)
💡 Suggestions:
• Make sure you're in a Django project directory
• A Django project contains a manage.py file
• Try: mercury-test --search-deep (searches everywhere)
• Navigate to your project root and try again
📚 Learn about Django project structure:
https://docs.djangoproject.com/en/stable/intro/tutorial01/
🆘 Need help? Run: mercury-test --list-plugins
Student plugins start with basics:
# Simple explanations
"N+1 means too many database queries"
# Basic fixes
"Add .select_related('author')"
# Clear examples
"Before: 101 queries, After: 1 query"As you improve, explanations deepen:
# Deeper understanding
"N+1 occurs due to lazy loading in ORMs"
# Multiple solutions
"Options: select_related, prefetch_related, or denormalization"
# Trade-offs
"Memory vs queries: prefetch_related loads more data"Eventually, complex topics:
# Performance theory
"Consider query planning and index statistics"
# Architecture decisions
"Evaluate CQRS for read-heavy operations"
# Optimization strategies
"Profile-guided optimization with silk"Mercury tracks your learning journey:
# View your progress
mercury-test --learn --progress
📊 YOUR LEARNING PROGRESS
═══════════════════════════════════════
Topics Completed:
✅ N+1 Queries (Quiz score: 8/10)
✅ Basic Indexing (Quiz score: 9/10)
🔄 Caching Strategies (In progress: 60%)
⭕ Advanced Optimization (Not started)
Total Score: 750 points
Level: Intermediate
Next Goal: Complete Caching Strategies[profiles.student]
quiz_difficulty = "intermediate" # beginner, intermediate, advanced
explanation_detail = "high" # low, medium, high
show_technical_details = false# Just want the wizard today
mercury-test --wizard --no-learn --no-hints
# Skip hints for this session
mercury-test --no-hints
# Extra detailed explanations
mercury-test --explain-everythingmercury-test --wizardLearn test organization before diving into performance.
# Dedicate 10 minutes daily to learning
mercury-test --learn --daily-lessonAfter each lesson, try fixing real issues:
# Before learning
class SlowView(APIView):
def get(self, request):
users = User.objects.all()
# N+1: Fetches profile for each user
return [{"name": u.name, "bio": u.profile.bio}
for u in users]
# After learning
class FastView(APIView):
def get(self, request):
# Fix: Eager load profiles
users = User.objects.select_related('profile')
return [{"name": u.name, "bio": u.profile.bio}
for u in users]# Weekly progress check
mercury-test --learn --weekly-reportQuizzes reinforce learning:
# Quick quiz before coding
mercury-test --learn --quick-quizWhen you're ready to graduate:
- Consistently scoring 9/10 on quizzes
- Fixing issues without hints
- Understanding trade-offs
- Comfortable with manual testing
# Try intermediate profile
mercury-test --profile intermediate
# Eventually move to expert
mercury-test --profile expert# Expert who still wants to learn
[profiles.expert_learner]
plugins.enabled = ["discovery", "learn"]
plugins.disabled = ["wizard", "hints"]
learn.difficulty = "advanced"Join the community to share learning:
- Discord: Share quiz scores
- GitHub: Contribute quiz questions
- Blog: Write about what you learned
- Answer questions in discussions
- Create custom learning content
- Mentor newcomers
- Ready for efficiency? Check Expert Plugins
- Want automation? Explore Agent Plugins
- Create learning content? See Contributing Tutorials
Remember: Every expert was once a student. There's no shame in learning, only in not trying.