This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients brett.cannon, eric.araujo, ezio.melotti, r.david.murray, serhiy.storchaka, skrah, terry.reedy, zach.ware
Date 2013-01-01.17:39:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1357061998.15.0.250829906305.issue16748@psf.upfronthosting.co.za>
In-reply-to
Content
I just came across the problem described here while reviewing #16694.

The idiom I used for the JSON tests[0] (and possibly a couple of other tests) when I rewrote them was to have something like:

class FooTest:
    # all the test methods here

class CFooTest(FooTest, unittest.TestCase):
    module = c_foo

class PyFooTest(FooTest, unittest.TestCase):
    module = py_foo

The reason to only have the subclasses inheriting from unittest.TestCase was exactly to avoid having FooTest as a discoverable TestCase.

I think PEP 399 should be updated and the tests should be fixed.
I don't think it's necessary to provide a base class as suggested in the first message (it's actually not even necessary to set the module to None, because eventually it will be set to either some cmodule or pymodule.  In case something goes wrong it's even better if the AttributeError says "self has no attribute 'module'" rather than "NoneType has no attribute 'somemeth'".)

@Brett, should I open a separate issue for the PEP 399 changes?

[0] see e.g.: Lib/test/json_tests/test_float.py and Lib/test/json_tests/__init__.py (note that here the idiom is a bit more complicated, because in addition to set the self.module, I also had to set additional attributes and work with different test files in the same package.  I also added additional tests in __init__ to make sure that import_fresh_module worked after adapting it to work with packages.)
History
Date User Action Args
2013-01-01 17:39:58ezio.melottisetrecipients: + ezio.melotti, brett.cannon, terry.reedy, eric.araujo, r.david.murray, skrah, zach.ware, serhiy.storchaka
2013-01-01 17:39:58ezio.melottisetmessageid: <1357061998.15.0.250829906305.issue16748@psf.upfronthosting.co.za>
2013-01-01 17:39:58ezio.melottilinkissue16748 messages
2013-01-01 17:39:57ezio.melotticreate