0

I have one abstract class

class Model:
    model_data: ModelData = None

    def write(self):
        raise NotImplementedError("write() must be implemented by {}".format(type(self).__name__))

    def read(self):
        raise NotImplementedError("read() must be implemented by {}".format(type(self).__name__))

I wonder how should I write the unit test using pytest for the read and write methods within this abstract class.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
zeelol
  • 33
  • 5
  • What is the goal of your test? If the goal is to check that subclasses that don't implement `read`/`write` will raise an error, then you can subclass in your test, call `read`/`write` and assert that an exception was raised. – Gino Mempin Mar 07 '21 at 06:48
  • Does this answer your question? [Testing abstract classes in Python](https://stackoverflow.com/questions/18549116/testing-abstract-classes-in-python) – Gino Mempin Mar 07 '21 at 06:48
  • Does this answer your question? [Python - Testing an abstract base class](https://stackoverflow.com/questions/9757299/python-testing-an-abstract-base-class) – MrBean Bremen Mar 07 '21 at 07:55

0 Answers0