Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30647
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: unit testing class hierarchies |
| Date | 2012-10-02 19:38 +0200 |
| Organization | None |
| References | <v53rj9-5kd.ln1@satorlaser.homedns.org> <mailman.1725.1349186875.27098.python-list@python.org> <irirj9-sme.ln1@satorlaser.homedns.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1733.1349199551.27098.python-list@python.org> (permalink) |
Ulrich Eckhardt wrote:
> Am 02.10.2012 16:06, schrieb Thomas Bach:
>> On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote:
>>> As you see, the code for test_base() is redundant, so the idea is to
>>> move it to a baseclass:
>>>
>>> class TestBase(unittest.TestCase):
>>> def test_base(self):
>>> ...
>>>
>>> class TestD1(TestBase):
>>> def test_r(self):
>>> ...
>>> def test_s(self):
>>> ...
>>>
>>> class TestD2(TestBase):
>>> def test_x(self):
>>> ...
>>> def test_y(self):
>>> ...
>>
>> Could you provide more background? How do you avoid that test_base()
>> runs in TestD1 or TestD2?
>
> Sorry, there's a misunderstanding: I want test_base() to be run as part
> of both TestD1 and TestD2, because it tests basic functions provided by
> both classes D1 and D2. The instances of D1 and D2 are created in
> TestD1.setUp and TestD2.setUp and then used by all tests. There is no
> possible implementation creating such an instance for TestBase, since
> the baseclass is abstract.
>
> Last edit for today, I hope that makes my intentions clear...
>
> ;)
Ceterum censeo baseclassinem esse delendam ;)
$ cat test_shared.py
import unittest
class Shared(unittest.TestCase):
def test_shared(self):
pass
class D1(Shared):
def test_d1_only(self):
pass
class D2(Shared):
def test_d2_only(self):
pass
del Shared
unittest.main()
$ python test_shared.py -v
test_d1_only (__main__.D1) ... ok
test_shared (__main__.D1) ... ok
test_d2_only (__main__.D2) ... ok
test_shared (__main__.D2) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.000s
OK
$
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
unit testing class hierarchies Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-02 14:27 +0200
Re: unit testing class hierarchies Demian Brecht <demianbrecht@gmail.com> - 2012-10-02 07:05 -0700
Re: unit testing class hierarchies Thomas Bach <thbach@students.uni-mainz.de> - 2012-10-02 16:06 +0200
Re: unit testing class hierarchies Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-02 17:24 +0200
Re: unit testing class hierarchies Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-02 18:54 +0200
Re: unit testing class hierarchies Peter Otten <__peter__@web.de> - 2012-10-02 19:38 +0200
Re: unit testing class hierarchies Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-02 19:41 +0100
Re: unit testing class hierarchies Ben Finney <ben+python@benfinney.id.au> - 2012-10-03 08:30 +1000
Re: unit testing class hierarchies Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-03 01:20 +0000
Re: unit testing class hierarchies Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-03 10:33 +0100
Re: unit testing class hierarchies Terry Reedy <tjreedy@udel.edu> - 2012-10-03 16:14 -0400
Re: unit testing class hierarchies Peter Otten <__peter__@web.de> - 2012-10-02 16:32 +0200
Re: unit testing class hierarchies Fayaz Yusuf Khan <fayaz@dexetra.com> - 2012-10-02 20:35 +0530
Re: unit testing class hierarchies Peter Otten <__peter__@web.de> - 2012-10-02 19:40 +0200
Re: unit testing class hierarchies Roy Smith <roy@panix.com> - 2012-10-02 19:46 -0400
csiph-web