Best strategy for testing class and subclasses in pytest?

C.D. Reimer chris at
Sat Aug 22 21:31:18 CEST 2015


I'm writing a chess engine to learn about Python classes and 
inheritance, and using pytest for the unit test. I've created a Piece 
class, which has 99% of the functionality for a chess piece, and 
subclass the other pieces -- Bishop, King, Knight, Pawn, Queen, Rook -- 
that will implement the move-specific functionality. I'm not sure what's 
the best strategy is for testing the class and subclasses.

I initially wrote unit tests for the class and subclasses (including 
tests for class-only functionality). That worked well until I started 
refactoring code and breaking the tests. Too much copy, paste and 
renaming for my taste.

I tried to create a separate class and/or module to import the common 
tests for each class and subclass. My attempts often ended in failure 
with the "RuntimeError: super(): no arguments" message. I couldn't find 
a working example on the Internet on how to do that. The pytest 
documentation is all over the place.

Is there a way to reuse tests in pytest?

Or should I test everything in the class and test only the implemented 
functionality in the subclasses?

Thank you,

Chris R.

More information about the Python-list mailing list