Top Banner
Mashing up py.test, coverage.py and ast.py to take TDD to a new level Tibor Arpas tibor@infin it.sk
26
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Europython 2015 Testmon

Mashing up py.test, coverage.py and ast.py to take TDD to a new level

Tibor [email protected]

Page 2: Europython 2015 Testmon

● freelancer● but not “only”● only Python since 2008

Tibor Arpáš - about me

Page 3: Europython 2015 Testmon

About you

Page 4: Europython 2015 Testmon

Users hate waiting

● 100 milliseconds● 1 second● 10 seconds

Page 5: Europython 2015 Testmon

So computing adapts

● big improvement in recent years

Page 6: Europython 2015 Testmon

Executing test suite

Page 7: Europython 2015 Testmon
Page 8: Europython 2015 Testmon

It’s easy to slip

● and one bad commitcan start a downwardspiral

● quality and effectivitydecline

Page 9: Europython 2015 Testmon

Broken test suite

● error lifespan increase● punishment of the

developers who are diligent

Page 10: Europython 2015 Testmon

But …

● how about running just affected tests?

Page 11: Europython 2015 Testmon

Majority of code changes are local

• waste to run the whole test suite each time

Page 12: Europython 2015 Testmon

Tests hand picking

• good luck beeing correct every time

Page 13: Europython 2015 Testmon

When the dependencies look like this

Page 14: Europython 2015 Testmon

Example “project” with a test suite in one file

Page 15: Europython 2015 Testmon

Dependencies

Page 16: Europython 2015 Testmon

subtract vs. test_add

Page 17: Europython 2015 Testmon

Dependencies

Page 18: Europython 2015 Testmon
Page 19: Europython 2015 Testmon

Idea transformed into a tool: testmon.org

Page 20: Europython 2015 Testmon

coverage.py

..coverage.start()code_to_track()coverage.stop()

coverage.data..

Page 21: Europython 2015 Testmon

ast.py (standard library)

import ast

tree = ast.parse(source_code, file_name)

things that helped me to understand:• https://github.com/mitsuhiko/pyastutil -

> codegen.py• ast.dump

Page 22: Europython 2015 Testmon

py.test plug-in

• py.test’s plugin API is nice

• just a couple of lines

Page 23: Europython 2015 Testmon

Interesting aspect - crowdfunding

Page 24: Europython 2015 Testmon
Page 25: Europython 2015 Testmon

conclusion - testmon is awesome

● use● give feedback● share

Page 26: Europython 2015 Testmon

Contacts

Contacts again

[email protected]

Questions?