durranee
Posts: 16
Joined: Sat Apr 21, 2018 10:37 pm

TDD Pytest and GPIO

Fri May 04, 2018 10:43 am

Hi guys

Working on a project atm and wanted to TDD the script that I wrote to make my Pi car roam around.
Is there a way to mock or properly TDD the GPIO pins in pytest at all?

Thanks

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: TDD Pytest and GPIO

Fri May 04, 2018 11:36 am

Perhaps it depends on the library module you are using to interact with the GPIO pins?

The gpiozero Python library module, installed by default with current releases of Raspbian, has built-in support: http://gpiozero.readthedocs.io/en/stabl ... #mock-pins

For RPi.GPIO I'm sure I've seen a blog post describing how to craft a non-functional dummy module. But that module has a very small number of methods, so it would be trivial to create your own if you can't find that blog.

Just a hint that Testing doesn't have a very high profile here, so it might be useful to provide a definition of what you mean by TDD?

Edit: added - a few seconds with an Internet search tool and the string "RPi.gpio dummy" found -
https://pypi.org/project/fake-rpi/

and

https://raspberrypi.stackexchange.com/q ... developing (scroll down to the reply from skidoo.)

Return to “Python”