Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95565 > unrolled thread

Best strategy for testing class and subclasses in pytest?

Started by"C.D. Reimer" <chris@cdreimer.com>
First post2015-08-22 12:31 -0700
Last post2015-08-22 12:31 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Best strategy for testing class and subclasses in pytest? "C.D. Reimer" <chris@cdreimer.com> - 2015-08-22 12:31 -0700

#95565 — Best strategy for testing class and subclasses in pytest?

From"C.D. Reimer" <chris@cdreimer.com>
Date2015-08-22 12:31 -0700
SubjectBest strategy for testing class and subclasses in pytest?
Message-ID<mailman.16.1440271885.17298.python-list@python.org>
Greetings,

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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web