@@ -52,52 +52,50 @@ def do_show_env():
5252 print (f" { env } = { os .environ [env ]!r} " )
5353
5454
55- def do_remove_extension ( * args ):
55+ def remove_extension ( core ):
5656 """Remove the compiled C extension, no matter what its name."""
5757
58+ if core == "ctrace" :
59+ return
60+
5861 so_patterns = """
5962 tracer.so
6063 tracer.*.so
6164 tracer.pyd
6265 tracer.*.pyd
6366 """ .split ()
6467
65- if "--from-install" in args :
66- # Get the install location using a subprocess to avoid
67- # locking the file we are about to delete
68- root = os .path .dirname (
69- subprocess .check_output (
70- [
71- sys .executable ,
72- "-Xutf8" ,
73- "-c" ,
74- "import coverage; print(coverage.__file__)" ,
75- ],
76- encoding = "utf-8" ,
77- ).strip (),
78- )
79- roots = [root ]
80- else :
81- roots = [
82- "coverage" ,
83- "build/*/coverage" ,
84- ".tox/*/[Ll]ib/*/site-packages/coverage" ,
85- ".tox/*/[Ll]ib/site-packages/coverage" ,
86- ]
68+ roots = [
69+ "coverage" ,
70+ "build/*/coverage" ,
71+ ".tox/*/[Ll]ib/*/site-packages/coverage" ,
72+ ".tox/*/[Ll]ib/site-packages/coverage" ,
73+ ]
8774
75+ # On windows at least, we can't delete a loaded .pyd file. So move them
76+ # out of the way into the tmp/ directory.
77+ os .makedirs ("tmp" , exist_ok = True )
8878 for root , pattern in itertools .product (roots , so_patterns ):
8979 pattern = os .path .join (root , pattern )
9080 if VERBOSITY > 1 :
9181 print (f"Searching for { pattern } from { os .getcwd ()} " )
9282 for filename in glob .glob (pattern ):
9383 if os .path .exists (filename ):
84+ hidden = f"tmp/{ os .path .basename (filename )} "
9485 if VERBOSITY > 1 :
95- print (f"Removing { os . path . abspath ( filename ) } " )
86+ print (f"Moving { filename } to { hidden } " )
9687 try :
97- os .remove (filename )
88+ if os .path .exists (hidden ):
89+ os .remove (hidden )
9890 except OSError as exc :
9991 if VERBOSITY > 1 :
100- print (f"Couldn't remove { os .path .abspath (filename )} : { exc } " )
92+ print (f"Couldn't remove { hidden } : { exc } " )
93+ else :
94+ try :
95+ os .rename (filename , hidden )
96+ except OSError as exc :
97+ if VERBOSITY > 1 :
98+ print (f"Couldn't rename: { exc } " )
10199
102100
103101def label_for_core (core ):
@@ -157,10 +155,10 @@ def make_env_id(core):
157155
158156def run_tests (core , * runner_args ):
159157 """The actual running of tests."""
158+ remove_extension (core )
160159 if "COVERAGE_TESTING" not in os .environ :
161160 os .environ ["COVERAGE_TESTING" ] = "True"
162161 print_banner (label_for_core (core ))
163-
164162 return pytest .main (list (runner_args ))
165163
166164
@@ -209,6 +207,8 @@ def run_tests_with_coverage(core, *runner_args):
209207 if getattr (mod , "__file__" , "??" ).startswith (covdir ):
210208 covmods [name ] = mod
211209 del sys .modules [name ]
210+ remove_extension (core )
211+
212212 import coverage # pylint: disable=reimported
213213
214214 sys .modules .update (covmods )
0 commit comments