3. Time - Taking up sys resources
•Python Profiler only shows CPU Time
•Use Unix time command to look at wall clock time &
CPU time, then subtract for an idea of I/O time
•lsof - lists open files, pass python id as the process
•Anything stand out? Possibly Django fixtures?
•Watch db logs
4. Time - Pull out methods
•Pull out methods into free functions
•Factor out the parts that don’t touch the attributes into
a separate free function
•Watch: Stop Mocking, Start Testing
•Classes should not be more than 50 lines?
5. Maintainable Testing
•New code? Design with testing in mind?
•Existing code? Don’t just write tests to write tests when
you can’t clearly approach the test writing process
•Think about how you can improve your code for testing
•Bad tests costs time
•Use system tests to make up for the lack of tests. :-/
6. Mocking
•Mimic behavior of real objects in controlled ways, i.e.
crash test dummy
•Talks to refer to:
•Fake It Till You Make It
•Stop Mocking, Start Testing
•Large Scale Testing
7. Testing in Django (must watch)
•Don’t write tests that test Django, test your apps
•Django’s test runner thinks tests are in one module
•Use __init__.py & import all submodules
•Don’t hit the db (Time)
•Don’t run tests on method that does a self.save()
•Fixtures - just say no; Hard to load & slow
8. Large Scale Tests
•Interesting note on Fixture bundling...
TestCase 1: A, B, C
TestCase 2: A, C, D
TestCase 3: A, B, C
• Nose can dynamically reorder
TestCase 1: A, B, C
TestCase 3: A, B, C
TestCase 2: A, C, D
9. Which talks to watch
• Testing in Django *****
• Fake It Til You Make It: Unit Testing Patterns With
Mocks and Fakes ***
• Speedily Practical Large-Scale Tests ****
• Stop Mocking, Start Testing ***
• Fast Test, Slow Test ***
• Certainty in an Uncertain World: Gaining Confidence
through Security Testing ***
• pytest - rapid and simple testing with Python **
• Building a Robot that Can Play Angry Birds on a
Smartphone *