Skip to content

Commit 8f594b9

Browse files
authored
Merge pull request #6 from AccelerationConsortium/copilot/mock-rpi-gpio-for-tests
Mock RPi.GPIO in tests for CI compatibility
2 parents 78eebdb + 20bbbd0 commit 8f594b9

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
- 2025-11-19: tests: Add tests/conftest.py to mock RPi.GPIO in CI so pytest can run in non-Raspberry Pi environments. (Fixes job 55770449647)
7+
38
## Version 0.1 (development)
49

510
- Feature A added

tests/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,37 @@
77
- https://docs.pytest.org/en/stable/writing_plugins.html
88
"""
99

10+
import sys
11+
import types
12+
13+
# Provide a minimal RPi.GPIO mock ONLY when running under pytest
14+
# This ensures the mock is never activated outside of test execution
15+
if 'pytest' in sys.modules or '_pytest' in sys.modules:
16+
rpi = types.ModuleType('RPi')
17+
gpio = types.ModuleType('RPi.GPIO')
18+
19+
def _noop(*args, **kwargs):
20+
return None
21+
22+
gpio.setmode = _noop
23+
gpio.setup = _noop
24+
gpio.cleanup = _noop
25+
gpio.input = lambda *args, **kwargs: 0
26+
gpio.output = _noop
27+
gpio.add_event_detect = _noop
28+
gpio.remove_event_detect = _noop
29+
30+
# common constants
31+
gpio.BOARD = 10
32+
gpio.BCM = 11
33+
gpio.IN = 0
34+
gpio.OUT = 1
35+
gpio.PUD_UP = 2
36+
gpio.PUD_OFF = 20
37+
gpio.LOW = 0
38+
39+
# register modules so `import RPi.GPIO as GPIO` works
40+
sys.modules['RPi'] = rpi
41+
sys.modules['RPi.GPIO'] = gpio
42+
1043
# import pytest

0 commit comments

Comments
 (0)