Open mattip opened 1 month ago
Is that a test-only issue, which we should fix by hacking at the tests? Or is that a real-world issue? I would think the former only, because if I understand it correctly it's only about the long-deprecated ffi.verify()
. Am I correct?
Also, wtf, these two tests are entirely identical to each other. I think they were originally not, but were refactored into that. We can just remove one of the copies. But I guess they are not the only case of the problem described here.
Yes, this is a test-only issue, and maybe only on windows. I see random test failures on macos too on the pypy buildbot after translation, but that might be something else.
This seems to work. It needs to hack both __init__
and verify
since comments are discarded when parsing, and any declaration needs a definition. Two tests also needed adjustment. Is there a cleaner work around?
Uh, hacking indeed. Maybe instead touch the code that comes up with the hash in the first place? Something like: if you set an undocumented attribute on the FFI class, then ffi.verify()
won't generate a hash, but instead use that hash directly. Requires a small change in the non-test source code, but it's cleaner IMHO.
Or just a new keyword argument passed to ffi.verify()
, with verify()
overridden in test classes like you do, to pass _force_hash=some_long_random_string
According to the sources, you can either insert a comment in the first argument to ffi.verify()
---which should influence the hash---or you can pass an explicit name with the modulename
keyword argument, which overrides the hash computation completely.
you can pass an explicit name with the modulename keyword argument
+1
I am working on fixing this in #83 to allow running the tests concurrently.
Sorry, I didn't see #83 before working on #135 which is passing CI with pytest-xdist enabled.
When running tests with pytest-xtest, different test runs will try to compile the test code in the same
__pycache__
directory. If the tests contain the same C code, this will lead to a situation where two tests are trying to build the same extension simultaneously, which can lead to compilation overwriting the same files, which will not work on windows (and perhaps elsewhere).For instance, these tests will produce the same cffi source hash so calling
ffi.verify
will generate exactly the same object and linker outputOne possible mitigation could be to change the
__init__
of theFFI
class to add a random `ffi.cdef("/ %d /" % random.randint(0, 32_000))