Ezio Melotti added the comment:
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.)
----------
assignee: -> ezio.melotti
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue16748>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com