Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95565
| From | "C.D. Reimer" <chris@cdreimer.com> |
|---|---|
| Subject | Best strategy for testing class and subclasses in pytest? |
| Date | 2015-08-22 12:31 -0700 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16.1440271885.17298.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Best strategy for testing class and subclasses in pytest? "C.D. Reimer" <chris@cdreimer.com> - 2015-08-22 12:31 -0700
csiph-web