TheDigitalCatOnline / blog_source

Source code of the blog
16 stars 6 forks source link

Please expand discussion of singleton class to include pytest tear down #18

Open drjasonharrison opened 3 years ago

drjasonharrison commented 3 years ago

It would be really helpful if the the pytest discussion pages included how to test a class that inherits from your metaclass=Singleton. This is an often ignored challenge in pytest, and Singleton, discussions.

https://www.thedigitalcatonline.com/blog/2014/09/01/python-3-oop-part-5-metaclasses/

lgiordani commented 3 years ago

Hi! Sorry for the late answer. I haven't reviewed that post for a long time. Can you please elaborate, I'm not sure I follow exactly which pytest discussion you are referring to in that post. Thanks!

drjasonharrison commented 3 years ago

In your other discussion on TDD, you covered patching, which is just about the only way to test a Singleton class when it is used by another class. https://www.thedigitalcatonline.com/blog/2020/09/21/tdd-in-python-with-pytest-part-5/

In trying to write tests for a Singleton class I found that most of the discussions about TDD and most of the discussions about Singletons there was either very poor or no discussion of how to test a class that relies on a singleton class.