PyTestforDataScience_PyDataLA
PyTestforDataScience_PyDataLA copied to clipboard
Pytest for Data Science Beginners
Pytest for Data Science
Pytest for Data Science Beginners. No prior testing knowledge is assumed!
This is a tutorial given at PyData Los Angeles 2018
Goal
Introduce testing philosophy and code. By end of tutorial attendees will be able to write pytest unit tests themselves. Specifically they will know about
- Pytest test patterns
- Pytest Fixures
- Mock
- Monkeypatch
- References to advanced topics such as parameterized tests and test runner configuration
Agenda
Introduction
About the speaker and format of talk
Is testing needed in Data Science?
Spoiler alert, yes. Testing is widely used in serious data science. We'll cover examples and real world cases.
Instructor Examples and Attendee activities
This tutorial will have plenty of hands on activities. Each section below will have an instructor explanation followed with a student challenge.
How pytest works and writing a basic test
We'll cover how to structure tests for use with pytest, and also an example of why pytest is the preferred testing framework for many projects
Test Fixtures
Fixtures are an important component of testing that allows for reuse of mutable data structures. If this doesn't make sense now it will after going through this example.
Mock
Loading data or running a model sometimes takes minutes or even hours. We'll see how mock can be used to "fake" python data structures to make writing and running tests faster and more isolated.
Monkey Patch
In data science you'll frequently be using other peoples libraries. This example will show how to alter functionality during testing time and why this is sometimes desired.
Next steps and advanced topics
We'll have an open discussion about functionality such as parametrization, test finalizers, exception testing, and code coverage
SpeakerRate
Feedback on this talk is welcome! https://speakerrate.com/events/18193-pydata-los-angeles-2018