1

I have a base contract class which can be inherited to provide plugin functionality. I'm adding the new plugins using setuptools entrypoints something like

entry_points="""
[plugins]
plugin1=plugins.plugin1:Plugin1
"""

And classes look like...

class Plugin:
    __metaclass__ = abc.ABCMeta

    @abstractmethod
    def must_override_method():
        pass

    @abstractmethod
    def must_override_method2():
        pass


#./plugins/plugin1.py
#Actually the plugins could be anywhere

class Plugin1(Plugin):

    def must_override_method():
        print("Hello")

Although the @abstracmethod doesn't let me instantiate the class at runtime if must_override_methods are not defined but how should I go about adding unit tests for the plugins that are not yet written.

Is there a simple way to write generic test that catches "plugins" that don't implement abstract methods while testing?

1 Answer 1

1

I think, the best way is to use mocking for that abstract class. Mocking is a mechanism where it won't really creates an object or try to create. Rather, It will create a mock object which will have same properties. please use mock module for the same

Sign up to request clarification or add additional context in comments.

1 Comment

I don't think this solves the issue since I'm not trying to test the response or implementation of any method. I'm try to test whether the plugins are valid or not by checking if they call be instantiated properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.