I have python code running on a custom SBC, and it uses a custom library to interact with the hardware (call it customlib).
However, I'd like to run some unit tests on the code on my dev machine. I don't want to install this custom library on my machine because it's a laborious and annoying process.
Question: is it possible to patch that library so I can still run unit tests on my dev machine?
app structure:
.
├── app.py
├── sensor
│ ├── __init__.py
│ └── main.py
└── test_sensor.py
app.py doesn't have any code at the moment
# __init__.py
from .main import a
# main.py
import customlib
def a():
customlib.func()
# test_sensor.py
import unittest
from unittest.mock import patch
class TestBasicSense(unittest.TestCase):
@patch("sensor.customlib")
def test_get(self):
import sensor
sensor.a()
if __name__ == "main":
unittest.main()
When I run python -m unittest I'm getting the import error:
File "/projects/myapp/sensor/main.py", line 2, in <module>
import customlib
ModuleNotFoundError: No module named 'customlib'
I could create a dummy customlib library and install it on my dev machine, but that seems like unnecessary pollution.
Any help is appreciated.