Skip to content

Use MagicMock if GPIO import fails #86

Description

@alxwrd

I had a thought (when commenting on #62) that when trying to import GPIO, on an import error we could switch it out for MagicMock. This would mean there wouldn't be any need to set Config.test_mode = True as the mock object would just silently 'run' GPIO methods.

from unittest.mock import MagicMock

try:
    import RPi.GPIO as GPIO
except ImportError:
    GPIO = MagicMock()

I'm not 100% on this as it feels a bit hacky to use a testing mock object in the main module. Thoughts?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions