0

I am developing a python application that is deployed to a raspberry pi. It uses the RPi package which allows the application to connect to the GPIO of the Pi.

I am currently developing the application on Windows and firstly would like to be able to run the application on my windows PC but secondly when I write unit tests I would like to be able to run the tests autonomously and be able to change how the mock RPi behaves to simulate errors.

What are the best practices within python to substitute a package so that it runs normally on the Pi using the real RPi packages and also automatically runs the mocked package?

ed-wright
  • 73
  • 1
  • 12
  • 1
    Both unittest and pytest have mocking capabilities: https://docs.python.org/3/library/unittest.mock.html https://pypi.org/project/pytest-mock/ – Matteo Ragni Apr 29 '21 at 11:38
  • Thanks for the guidance, for normal use outside of testing, i.e. is it still best practice to use mocking to be able to 'run' the application on my desktop? – ed-wright Apr 29 '21 at 18:00
  • 1
    I can only give you my opinion, and it's something like: depends on specific case. Apart from opinions there questions and answers about mocking in integration testing that are for sure more relevant than my opinion: https://stackoverflow.com/questions/52107522/is-it-in-considered-a-good-practice-to-mock-in-integration-test – Matteo Ragni Apr 29 '21 at 20:17

0 Answers0