Path: csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subclass': 0.09; 'subclasses': 0.09; 'python': 0.10; 'pytest': 0.16; 'refactoring': 0.16; 'renaming': 0.16; 'subclasses.': 0.16; 'subject:class': 0.16; 'subject:strategy': 0.16; 'subject:subclasses': 0.16; 'test.': 0.18; 'tests.': 0.18; 'tests': 0.18; 'class,': 0.22; 'from:addr:chris': 0.22; 'wrote': 0.23; 'tried': 0.24; 'import': 0.24; 'implemented': 0.24; 'module': 0.25; 'testing': 0.25; "i've": 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'chris': 0.26; 'separate': 0.27; 'pieces': 0.27; 'received:dreamhost.com': 0.29; 'received:g.dreamhost.com': 0.29; "i'm": 0.30; '(including': 0.30; 'classes': 0.30; 'that.': 0.30; 'code': 0.30; 'initially': 0.30; 'implement': 0.32; 'received:10.0.0': 0.32; 'class': 0.33; 'message.': 0.33; 'common': 0.33; 'worked': 0.34; 'received:10.0': 0.34; 'unit': 0.35; 'too': 0.36; 'should': 0.36; 'there': 0.36; 'created': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'received:10': 0.37; 'thank': 0.38; 'test': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'greetings,': 0.61; 'engine': 0.62; 'reuse': 0.66; 'strategy': 0.69; 'internet': 0.70; 'inheritance,': 0.93; 'subject:Best': 0.93 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cdreimer.com; h=to:from :subject:message-id:date:mime-version:content-type :content-transfer-encoding; s=cdreimer.com; bh=IFyu9KXL2gYFVpHJi gmueuZrBcQ=; b=zmBfIld6jn1spmrVKwCyUAYwDTIbDQmfsah0JylMFgWU5J4k1 b90Yf/3DgsR1FQcNhotmjm/wPEmV9HFMNex4cniFr1RypgKqOvyLL8m5H9Slaao6 Y0fCUmvsp1g7IR+eaGPhJgadGmjLkn0PI0EqaNmHtW8Ei9PnKdIwpTBzTM= To: python-list@python.org From: "C.D. Reimer" Subject: Best strategy for testing class and subclasses in pytest? Date: Sat, 22 Aug 2015 12:31:18 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440271885 news.xs4all.nl 23840 [2001:888:2000:d::a6]:51657 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 4259 X-Received-Body-CRC: 4058765537 Xref: csiph.com comp.lang.python:95565 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.