New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_heapq C tests are not skipped when _heapq is missing #56119
Comments
When _heapq is missing, test_heapq still runs both the Py and the C tests instead of skipping the C ones. The attached patch skips the C tests when _heapq is missing. |
Patch seems good. Ezio, can you commit?. |
Attempting to fix import_fresh_module might be better. |
Are you sure those tests are C specific? Please be careful about doing unnecessary complexification of this module's tests. |
If they are not C specific they should be moved to the base class (TestHeap). TestHeapC and TestHeapPython should contain only tests specific to the C and Python versions respectively. The goal here is to make sure that they are run once with the Python version, and again with the C version -- but only if the C version is available. c_heapq = import_fresh_module('heapq', fresh=['_heapq']) should be fixed to try to import _heapq and return None if the import fails, so that a @skipUnless(c_heapq, 'test requires the _heapq module') decorator can be added to TestHeapC.
See also http://www.python.org/dev/peps/pep-0399/ This can be fixed in 2.7 first. |
Some of the tests were incorrectly marked as being C specific. I've fixed that on the 2.7 branch. Re-assigning back to Ezio. Overall, I don't think the current approach to testing both paths is elegant. Is there some alternative approach to running suites in two different context without adding .module indirections and multiple subclasses throughout the code? |
I'm imagining a cleaner testing style, like this: class TestHeap(unittest.TestCase):
def test_nsmallest(self):
self.assertEqual(heapq.nsmallest(3, range(10)), [0,1,2])
...
def test_main(verbose=None):
test_classes = [TestHeapPython, TestErrorHandling]
test_support.run_unittest(*test_classes)
test_support.reload('heapq', hiding='_heapq')
test_support.run_unittest(*test_classes) Ideally, we should be able to hide individual methods and be able to mark entire test classes with decorators for required features. |
Thanks (for the record the changeset is a8b82c283524).
@skipUnless(is_cypthon and c_foo)
class CFooTests(PythonTest):
...
@skipUnless(is_jython and j_foo)
class JFooTests(PythonTest):
... This also avoid to list the tests explicitly at the end to exclude the base class (e.g. currently we have to exclude TestHeap, and list TestHeapC and TestHeapPy). We could come up with some smart class decorator that runs a set of tests with and without accelerations, but it will make more difficult to add tests specific to the C or Python versions. |
Attaching a rough draft of a way to simplify dual path testing. The idea is that the suite shouldn't have to be rewritten with self.module.heapify(...) references throughout. Instead, tests are written normally and the only thing that changes in the context that they are executed in (not much different that if we simply commented out the import of c accelerator code). Several things need work:
The patch is a proof-of-concept that would need polishing before becoming the preferred way of doing multiple path testing. |
Attached a patch that fixes import_fresh_module to return None when _heapq is missing and skips the C test when _heapq is missing. I also added an additional test to verify that the functions in c_heapq are really C functions and the ones in py_heapq are really Python functions. |
BTW, if the fix for import_fresh_module is OK, it should be committed separately. |
New changeset c1a12a308c5b by Ezio Melotti in branch '2.7': |
New changeset 3ab1eb027856 by Ezio Melotti in branch '3.1': New changeset 754bafe8db5f by Ezio Melotti in branch '3.2': New changeset 3e8f0111feed by Ezio Melotti in branch 'default': |
New changeset 3cbbb2a7c56d by Ezio Melotti in branch '2.7': New changeset 677ee366c9f5 by Ezio Melotti in branch '3.1': New changeset 4f3f67a595fb by Ezio Melotti in branch '3.2': New changeset 3449406fd04a by Ezio Melotti in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: