Slide 1

Slide 1 text

@easyaspython PyOo !1

Slide 2

Slide 2 text

@easyaspython Adopt-a-pytest PyOhio 2019 Dane Hillard Lead Web Application Developer !2

Slide 3

Slide 3 text

@easyaspython About me Reasons to pytest How to pytest More reasons to pytest !3

Slide 4

Slide 4 text

@easyaspython What’s a Dane? !4

Slide 5

Slide 5 text

@easyaspython ! Developing in Python (and Django) for ~7 years ! Web app development for ~4 years ! I do hobbies ○ Lifestyle photographer ○ Musician ○ Epicurean ○ Competitive ballroom dancer ○ Blogger ○ Author !5

Slide 6

Slide 6 text

@easyaspython Practices of the Python Pro ! bit.ly/the-python-pro ! Gentle intro to software design practices !6

Slide 7

Slide 7 text

@easyaspython !7

Slide 8

Slide 8 text

@easyaspython !8

Slide 9

Slide 9 text

@easyaspython !9 ! 50+ apps ! 900+ modules ! 300+ test modules ! 2K+ tests Before: Manual, occasional, often broken Now: Automated*, every commit, not broken

Slide 10

Slide 10 text

@easyaspython What’s a pytest? !10

Slide 11

Slide 11 text

@easyaspython Simpler syntax !11

Slide 12

Slide 12 text

@easyaspython !12

Slide 13

Slide 13 text

@easyaspython !13

Slide 14

Slide 14 text

@easyaspython !14

Slide 15

Slide 15 text

@easyaspython !15

Slide 16

Slide 16 text

@easyaspython Fixtures !16

Slide 17

Slide 17 text

@easyaspython !17

Slide 18

Slide 18 text

@easyaspython !18

Slide 19

Slide 19 text

@easyaspython !19

Slide 20

Slide 20 text

@easyaspython !20

Slide 21

Slide 21 text

@easyaspython Marks, patterns, filtering !21

Slide 22

Slide 22 text

@easyaspython !22

Slide 23

Slide 23 text

@easyaspython !23

Slide 24

Slide 24 text

@easyaspython !24

Slide 25

Slide 25 text

@easyaspython !25

Slide 26

Slide 26 text

@easyaspython Durations !26

Slide 27

Slide 27 text

@easyaspython !27

Slide 28

Slide 28 text

@easyaspython Parallels for most unittest stuff !28

Slide 29

Slide 29 text

@easyaspython !29

Slide 30

Slide 30 text

@easyaspython pytest is lovely !30

Slide 31

Slide 31 text

@easyaspython Retrofitting is hard !31

Slide 32

Slide 32 text

@easyaspython Step 0: Create a baseline !32

Slide 33

Slide 33 text

@easyaspython !33

Slide 34

Slide 34 text

@easyaspython Step 1: Install pytest !34

Slide 35

Slide 35 text

@easyaspython !35

Slide 36

Slide 36 text

@easyaspython Step 1a: Install pytest-cov !36

Slide 37

Slide 37 text

@easyaspython Step 2: Run pytest !37

Slide 38

Slide 38 text

@easyaspython !38

Slide 39

Slide 39 text

@easyaspython !39

Slide 40

Slide 40 text

@easyaspython !40

Slide 41

Slide 41 text

@easyaspython !41

Slide 42

Slide 42 text

@easyaspython Step 3: Fix test collection !42

Slide 43

Slide 43 text

@easyaspython Test discovery !43 Convention unittest pytest Ⓜ test*.py ✅ Ⓜ test_*.py ✅ ✅ Ⓜ *_test.py ✅ Ⓜ *_tests.py Ⓒ *(unittest.TestCase) ✅ ✅ ⓜ test_* ✅ ✅ Ⓒ Test* ✅ ⓜ test_* ✅ ⓕ test_* ✅

Slide 44

Slide 44 text

@easyaspython !44

Slide 45

Slide 45 text

@easyaspython !45

Slide 46

Slide 46 text

@easyaspython Option A: Rename test modules !46

Slide 47

Slide 47 text

@easyaspython Option B: pytest.ini !47

Slide 48

Slide 48 text

@easyaspython !48

Slide 49

Slide 49 text

@easyaspython !49

Slide 50

Slide 50 text

@easyaspython !50

Slide 51

Slide 51 text

@easyaspython Step 4: Shim things !51

Slide 52

Slide 52 text

@easyaspython conftest.py !52

Slide 53

Slide 53 text

@easyaspython !53

Slide 54

Slide 54 text

@easyaspython !54

Slide 55

Slide 55 text

@easyaspython Step 5: Use pytest in new tests !55

Slide 56

Slide 56 text

@easyaspython Step 6: Rewrite old tests !56

Slide 57

Slide 57 text

@easyaspython Step 7: Use helpful plugins !57

Slide 58

Slide 58 text

@easyaspython Step 8: Integrate with CI/CD !58

Slide 59

Slide 59 text

@easyaspython Incremental !59

Slide 60

Slide 60 text

@easyaspython Helpful fallbacks !60

Slide 61

Slide 61 text

@easyaspython Adopt and embrace !61

Slide 62

Slide 62 text

@easyaspython What else is a pytest? !62

Slide 63

Slide 63 text

@easyaspython Parameterization !63

Slide 64

Slide 64 text

@easyaspython !64

Slide 65

Slide 65 text

@easyaspython !65

Slide 66

Slide 66 text

@easyaspython !66

Slide 67

Slide 67 text

@easyaspython !67

Slide 68

Slide 68 text

@easyaspython !68

Slide 69

Slide 69 text

@easyaspython !69

Slide 70

Slide 70 text

@easyaspython !70

Slide 71

Slide 71 text

@easyaspython !71

Slide 72

Slide 72 text

@easyaspython !72

Slide 73

Slide 73 text

@easyaspython Works with Jenkins !73

Slide 74

Slide 74 text

@easyaspython Works with tox !74

Slide 75

Slide 75 text

@easyaspython Plugin-based architecture (pluggy) !75

Slide 76

Slide 76 text

@easyaspython pytest pytest-cov pytest-django pytest-randomly !76

Slide 77

Slide 77 text

@easyaspython !77

Slide 78

Slide 78 text

@easyaspython Thanks !78