diff --git a/RPi/core.py b/RPi/core.py index 3137b74..3c83115 100644 --- a/RPi/core.py +++ b/RPi/core.py @@ -1046,7 +1046,7 @@ def setmode(mode): BOARD - Use Raspberry Pi board numbers BCM - Use Broadcom GPIO 00..nn numbers """ - if _State.mode != UNKNOWN: + if _State.mode != UNKNOWN and _State.mode != mode: raise ValueError("A different mode has already been set!") if mode != BCM and mode != BOARD: diff --git a/tests/test_gpio.py b/tests/test_gpio.py index 3cd0568..dac22e7 100644 --- a/tests/test_gpio.py +++ b/tests/test_gpio.py @@ -41,6 +41,16 @@ def test_is_iterable(): assert GPIO_DEVEL.is_iterable(i) is True +@pytest.mark.parametrize('GPIO_MODE', [GPIO.BCM, GPIO.BOARD]) +def test_setmode_remain_silent_in_same_mode(GPIO_MODE): + GPIO_DEVEL.Reset() + GPIO.setmode(GPIO_MODE) # Set a mode first + try: + GPIO.setmode(GPIO_MODE) # Expect there is not exception being raised + except ValueError: + pytest.fail('Failed to due double setup') + + def test_setmode_raise_double_setup_exception(): GPIO_DEVEL.Reset() with pytest.raises(Exception):