Skip to content
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

rename possibly identical modules to prevent test collisions #135

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions testing/cffi0/test_verify.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import pytest
import sys, os, math, weakref
import sys, os, math, weakref, random
from cffi import FFI, VerificationError, VerificationMissing, model, FFIError
from testing.support import *
from testing.support import extra_compile_args, is_musl
Expand All @@ -18,9 +18,19 @@
if distutils.ccompiler.get_default_compiler() == 'msvc':
lib_m = ['msvcrt']
pass # no obvious -Werror equivalent on MSVC
class FFI(FFI):
def verify(self, *args, **kwds):
modulename = kwds.get("modulename", "_cffi_test%d_%d" % (
random.randint(0,1000000000), random.randint(0,1000000000)))
kwds["modulename"] = modulename
return super(FFI, self).verify(*args, **kwds)

else:
class FFI(FFI):
def verify(self, *args, **kwds):
modulename = kwds.get("modulename", "_cffi_test%d_%d" % (
random.randint(0,1000000000), random.randint(0,1000000000)))
kwds["modulename"] = modulename
return super(FFI, self).verify(
*args, extra_compile_args=extra_compile_args, **kwds)

Expand Down Expand Up @@ -2164,21 +2174,23 @@ def test_verify_dlopen_flags():
ffi1 = FFI()
ffi1.cdef("extern int foo_verify_dlopen_flags;")

modulename = "_cffi_test_verify_dlopen_flags_%d" % random.randint(0, 1000000000)
lib1 = ffi1.verify("int foo_verify_dlopen_flags;",
flags=ffi1.RTLD_GLOBAL | ffi1.RTLD_LAZY)
lib2 = get_second_lib()
flags=ffi1.RTLD_GLOBAL | ffi1.RTLD_LAZY,
modulename=modulename)
lib2 = get_second_lib(modulename)

lib1.foo_verify_dlopen_flags = 42
assert lib2.foo_verify_dlopen_flags == 42
lib2.foo_verify_dlopen_flags += 1
assert lib1.foo_verify_dlopen_flags == 43

def get_second_lib():
# Hack, using modulename makes the test fail
def get_second_lib(modulename):
ffi2 = FFI()
ffi2.cdef("extern int foo_verify_dlopen_flags;")
lib2 = ffi2.verify("int foo_verify_dlopen_flags;",
flags=ffi2.RTLD_GLOBAL | ffi2.RTLD_LAZY)
flags=ffi2.RTLD_GLOBAL | ffi2.RTLD_LAZY,
modulename=modulename)
return lib2

def test_consider_not_implemented_function_type():
Expand Down Expand Up @@ -2246,7 +2258,7 @@ def test_implicit_unicode_on_windows():

def test_use_local_dir():
ffi = FFI()
lib = ffi.verify("", modulename="test_use_local_dir")
lib = ffi.verify("", modulename="_cffi_test_use_local_dir")
this_dir = os.path.dirname(__file__)
pycache_files = os.listdir(os.path.join(this_dir, '__pycache__'))
assert any('test_use_local_dir' in s for s in pycache_files)
Expand Down
3 changes: 2 additions & 1 deletion testing/cffi0/test_vgen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

# This test file runs normally after test_vgen. We only clean up the .c
# sources, to check that it also works when we have only the .so. The
# tests should run much faster than test_vgen.
# tests used to run much faster than test_vgen, but since we randomize
# the module names, it needs to recompile everything.

def setup_module():
cffi.verifier.cleanup_tmpdir(keep_so=True)
Expand Down
Loading