-
Notifications
You must be signed in to change notification settings - Fork 2
Quick Start
smattymatty edited this page Aug 3, 2025
·
2 revisions
Get Django Mercury running in your Django project in under 5 minutes.
pip install django-mercury-performancefrom django_mercury import DjangoMercuryAPITestCase
class UserAPITestCase(DjangoMercuryAPITestCase):
def test_user_list(self):
# Mercury automatically monitors this test
response = self.client.get('/api/users/')
self.assertEqual(response.status_code, 200)
# Performance analysis happens automatically!from django_mercury import DjangoPerformanceAPITestCase, monitor_django_view
class AdvancedUserAPITestCase(DjangoPerformanceAPITestCase):
def test_user_search_performance(self):
with monitor_django_view("user_search") as monitor:
response = self.client.get('/api/users/search/?q=john')
# Make specific assertions
self.assertResponseTimeLess(monitor, 100) # Under 100ms
self.assertQueriesLess(monitor, 10) # Under 10 queries
self.assertNoNPlusOne(monitor) # No N+1 problemsWhen you run your tests, Mercury provides detailed performance feedback:
๐จ MERCURY PERFORMANCE DASHBOARD - UserAPITestCase
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐ Overall Status: EXCELLENT โ
โ ๐ Overall Grade: A (87.3/100) โ
โ ๐ Tests Executed: 3 โ
โ โฑ๏ธ Avg Response Time: 45.2ms โ
โ ๐ง Avg Memory Usage: 12.1MB โ
โ ๐๏ธ Total Queries: 8 (2.7 avg) โ
โ โ
N+1 Issues: None detected โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
class MyPerformanceTestCase(DjangoMercuryAPITestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Configure Mercury behavior
cls.configure_mercury(
enabled=True,
auto_scoring=True,
educational_guidance=True
)
# Set performance thresholds
cls.set_performance_thresholds({
'response_time_ms': 200, # Max 200ms
'query_count_max': 15, # Max 15 queries
'memory_overhead_mb': 30, # Max 30MB overhead
})Run your tests to verify Mercury is working:
python manage.py testYou should see Mercury's performance analysis in your test output!
- API Reference: Complete API documentation
- DjangoMercuryAPITestCase Examples: Beginner-friendly examples
- DjangoPerformanceAPITestCase Examples: Expert examples
- Architecture Overview: How Mercury works under the hood
- Getting Help: Where to ask questions
- Community Values: Our Fair, Free, Open principles
- GitHub Issues: Report problems
Welcome to the Django Mercury community! ๐