File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments