Skip to content

Student Plugins

smattymatty edited this page Aug 25, 2025 · 1 revision

Student Plugins - Learning While Testing

Every test failure is a learning opportunity. Student plugins transform Mercury from a testing tool into a performance education platform.

Philosophy: Education First

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

Enabling Student Mode

Quick Setup

# First time - creates mercury_config.toml with student profile
mercury-test --profile student

# Subsequent runs automatically use student profile
mercury-test

Configuration

# mercury_config.toml
[mercury]
profile = "student"

[profiles.student]
plugins.enabled = ["discovery", "wizard", "learn", "hints"]
educational_mode = true
show_explanations = true
quiz_difficulty = "beginner"

Core Student Plugins

🎓 Learn Plugin - Interactive Education

The learn plugin transforms testing into an educational experience:

Features

  • 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

Usage

# 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

Example Learning Session

$ 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!

Topics Available

  • 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

🧙 Wizard Plugin - Guided Test Selection

Perfect for beginners who don't know what to test:

Features

  • Interactive menu: Browse available tests
  • Smart suggestions: Recommends what to test
  • Visual feedback: Colors and icons for clarity
  • Pattern learning: Teaches Django test organization

Usage

# Start wizard mode
mercury-test --wizard

Example Wizard Session

$ 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

💡 Hints Plugin - Contextual Learning

Provides performance tips based on actual test results:

Features

  • 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

Example Hints

$ 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())"

Configuration

[plugins.hints]
threshold = 30.0  # Show hints after 30 seconds
show_parallel_hint = true
show_specific_test_hint = true
max_hints_per_session = 3

🔍 Discovery Plugin - Educational Mode

In student profile, the discovery plugin provides educational error messages:

Student-Friendly Errors

$ 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

Learning Progression

Beginner Level

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"

Intermediate Level

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"

Advanced Level

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"

Tracking Your Progress

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

Customizing Student Experience

Adjusting Difficulty

[profiles.student]
quiz_difficulty = "intermediate"  # beginner, intermediate, advanced
explanation_detail = "high"  # low, medium, high
show_technical_details = false

Selective Plugin Usage

# 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-everything

Tips for Student Success

1. Start with the Wizard

mercury-test --wizard

Learn test organization before diving into performance.

2. Use Learn Mode Regularly

# Dedicate 10 minutes daily to learning
mercury-test --learn --daily-lesson

3. Apply What You Learn

After 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]

4. Track Your Progress

# Weekly progress check
mercury-test --learn --weekly-report

5. Don't Skip the Quizzes

Quizzes reinforce learning:

# Quick quiz before coding
mercury-test --learn --quick-quiz

Moving Beyond Student Mode

When you're ready to graduate:

Signs You're Ready

  • Consistently scoring 9/10 on quizzes
  • Fixing issues without hints
  • Understanding trade-offs
  • Comfortable with manual testing

Transitioning to Expert

# Try intermediate profile
mercury-test --profile intermediate

# Eventually move to expert
mercury-test --profile expert

Keep Learning Features Available

# Expert who still wants to learn
[profiles.expert_learner]
plugins.enabled = ["discovery", "learn"]
plugins.disabled = ["wizard", "hints"]
learn.difficulty = "advanced"

Community Learning

Share Your Progress

Join the community to share learning:

  • Discord: Share quiz scores
  • GitHub: Contribute quiz questions
  • Blog: Write about what you learned

Help Other Students

  • Answer questions in discussions
  • Create custom learning content
  • Mentor newcomers

Next Steps


Remember: Every expert was once a student. There's no shame in learning, only in not trying.

Django Mercury Wiki

🏠 Overview

Clone this wiki locally