22
22
import requests
23
23
import subprocess
24
24
import time
25
-
26
25
from tempfile import TemporaryDirectory
27
26
27
+
28
+ import escapism
28
29
import pytest
29
30
import yaml
30
31
31
32
from repo2docker .__main__ import make_r2d
32
33
34
+ TESTS_DIR = os .path .abspath (os .path .dirname (__file__ ))
35
+
33
36
34
37
def pytest_collect_file (parent , path ):
35
38
if path .basename == "verify" :
@@ -38,12 +41,18 @@ def pytest_collect_file(parent, path):
38
41
return RemoteRepoList .from_parent (parent , fspath = path )
39
42
40
43
41
- def make_test_func (args ):
44
+ def make_test_func (args , skip_build = False ):
42
45
"""Generate a test function that runs repo2docker"""
43
46
44
47
def test ():
45
48
app = make_r2d (args )
46
49
app .initialize ()
50
+ if skip_build :
51
+
52
+ def build_noop ():
53
+ print ("Skipping build" )
54
+
55
+ app .skip_build = build_noop
47
56
if app .run_cmd :
48
57
# verify test, run it
49
58
app .start ()
@@ -184,14 +193,14 @@ def repo_with_submodule():
184
193
class Repo2DockerTest (pytest .Function ):
185
194
"""A pytest.Item for running repo2docker"""
186
195
187
- def __init__ (self , name , parent , args = None ):
196
+ def __init__ (self , name , parent , args = None , skip_build = False ):
188
197
self .args = args
189
198
self .save_cwd = os .getcwd ()
190
- f = parent .obj = make_test_func (args )
199
+ f = parent .obj = make_test_func (args , skip_build = skip_build )
191
200
super ().__init__ (name , parent , callobj = f )
192
201
193
202
def reportinfo (self ):
194
- return self .parent .fspath , None , ""
203
+ return ( self .parent .fspath , None , "" )
195
204
196
205
def repr_failure (self , excinfo ):
197
206
err = excinfo .value
@@ -217,11 +226,34 @@ def collect(self):
217
226
extra_args = yaml .safe_load (f )
218
227
args += extra_args
219
228
229
+ print (self .fspath .basename , self .fspath .dirname , str (self .fspath ))
230
+ # re-use image name for multiple tests of the same image
231
+ # so we don't run through the build twice
232
+ rel_repo_dir = os .path .relpath (self .fspath .dirname , TESTS_DIR )
233
+ image_name = f"r2d-tests-{ escapism .escape (rel_repo_dir , escape_char = '-' ).lower ()} -{ int (time .time ())} "
234
+ args .append (f"--image-name={ image_name } " )
220
235
args .append (self .fspath .dirname )
221
-
222
236
yield Repo2DockerTest .from_parent (self , name = "build" , args = args )
237
+
238
+ yield Repo2DockerTest .from_parent (
239
+ self ,
240
+ name = self .fspath .basename ,
241
+ args = args + ["./verify" ],
242
+ skip_build = True ,
243
+ )
244
+
245
+ # mount the tests dir as a volume
246
+ check_tmp_args = (
247
+ args [:- 1 ]
248
+ + ["--volume" , f"{ TESTS_DIR } :/io/tests" ]
249
+ + [args [- 1 ], "/io/tests/check-tmp" ]
250
+ )
251
+
223
252
yield Repo2DockerTest .from_parent (
224
- self , name = self .fspath .basename , args = args + ["./verify" ]
253
+ self ,
254
+ name = "check-tmp" ,
255
+ args = check_tmp_args ,
256
+ skip_build = True ,
225
257
)
226
258
227
259
0 commit comments