Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockFactory does not release pins on close() #1087

Open
jornj opened this issue Aug 22, 2023 · 1 comment
Open

MockFactory does not release pins on close() #1087

jornj opened this issue Aug 22, 2023 · 1 comment

Comments

@jornj
Copy link

jornj commented Aug 22, 2023

Operating system: Ubuntu 22.04.3 LTS
Python version: 3.9.7
Pi model: None.
GPIO Zero version: 1.6.2
Pin factory used: MockFactory

It appears that the MockFactory does not release pins on close().
Is there a better way to release pins in a pytest teardown_function?

from gpiozero import Device, DigitalInputDevice
from gpiozero.pins.mock import MockFactory

def test_mockfactory_releases_pins_on_close():
    Device.pin_factory = MockFactory()
    device = DigitalInputDevice("J8:10")
    Device.pin_factory.close()
    device = DigitalInputDevice("J8:10")

test_mockfactory_releases_pins_on_close()

This fails with
gpiozero.exc.GPIOPinInUse: pin 15 is already in use by <gpiozero.DigitalInputDevice object on pin GPIO15, pull_up=False, is_active=False>

@MusicalNinjaDad
Copy link

An example of how to do this is in the mock_factory fixture in tests/conftest.py
I've also raises PR #1107 to make these fixtures available for import in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants