11from collections import namedtuple
22import contextlib
33import glob
4+ import os
45import pprint
56import shutil
67import subprocess
1617
1718
1819class MockEnv :
19- '''Use this to work with mock. Mutliple instances are not safe.'''
20+ '''Use this to work with mock. Mutliple concurrent instances are safe.'''
2021 mock = ['mock' , '-r' , './mock.cfg' ]
2122
22- def __init__ (self ):
23+ def __init__ (self , worker_id ):
24+ self .worker_id = worker_id
2325 self ._run (['--init' ], check = True )
2426
27+ @property
28+ def root (self ):
29+ return 'taskotron-python-versions-{}' .format (self .worker_id )
30+
31+ @property
32+ def rootdir (self ):
33+ return os .path .join (os .path .abspath ('.' ), 'mockroots' , self .root )
34+
2535 def _run (self , what , ** kwargs ):
26- return subprocess .run (self .mock + what , ** kwargs )
36+ command = list (self .mock ) # needs a copy not to change in place
37+ command .append ('--config-opts=root={}' .format (self .root ))
38+ command .append ('--rootdir={}' .format (self .rootdir ))
39+ command .extend (what )
40+ return subprocess .run (command , ** kwargs )
2741
2842 def copy_in (self , files ):
2943 self ._run (['--copyin' ] + files + ['/' ], check = True )
@@ -52,12 +66,12 @@ def copy_out(self, directory, target, *, clean_target=False):
5266
5367
5468@pytest .fixture (scope = "session" )
55- def mock (request ):
69+ def mock (worker_id , request ):
5670 '''Setup a mock we can run Ansible tasks in under root'''
5771 if request .config .getoption ('--fake' ):
58- mockenv = FakeMockEnv ()
72+ mockenv = FakeMockEnv (worker_id )
5973 else :
60- mockenv = MockEnv ()
74+ mockenv = MockEnv (worker_id )
6175 files = ['taskotron_python_versions' ] + glob .glob ('*.py' ) + ['tests.yml' ]
6276 mockenv .copy_in (files )
6377 yield mockenv
@@ -187,8 +201,10 @@ def test_two_three_passed(results, request):
187201 assert results ['dist.python-versions.two_three' ].outcome == 'PASSED'
188202
189203
190- def test_two_three_failed (tracer ):
191- assert tracer ['dist.python-versions.two_three' ].outcome == 'FAILED'
204+ @pytest .mark .parametrize ('results' , ('tracer' ,))
205+ def test_two_three_failed (results , request ):
206+ results = request .getfixturevalue (results )
207+ assert results ['dist.python-versions.two_three' ].outcome == 'FAILED'
192208
193209
194210@pytest .mark .parametrize ('results' , ('tracer' , 'copr' , 'admesh' ))
@@ -207,8 +223,10 @@ def test_artifact_is_the_same(results, task, request):
207223 results ['dist.python-versions.' + task ].artifact )
208224
209225
210- def test_artifact_contains_two_three_and_looks_as_expected (tracer ):
211- result = tracer ['dist.python-versions.two_three' ]
226+ @pytest .mark .parametrize ('results' , ('tracer' ,))
227+ def test_artifact_contains_two_three_and_looks_as_expected (results , request ):
228+ results = request .getfixturevalue (results )
229+ result = results ['dist.python-versions.two_three' ]
212230 with open (result .artifact ) as f :
213231 artifact = f .read ()
214232
@@ -233,8 +251,11 @@ def test_naming_scheme_failed(results, request):
233251 assert results ['dist.python-versions.naming_scheme' ].outcome == 'FAILED'
234252
235253
236- def test_artifact_contains_naming_scheme_and_looks_as_expected (copr ):
237- result = copr ['dist.python-versions.naming_scheme' ]
254+ @pytest .mark .parametrize ('results' , ('copr' ,))
255+ def test_artifact_contains_naming_scheme_and_looks_as_expected (results ,
256+ request ):
257+ results = request .getfixturevalue (results )
258+ result = results ['dist.python-versions.naming_scheme' ]
238259 with open (result .artifact ) as f :
239260 artifact = f .read ()
240261
@@ -258,9 +279,11 @@ def test_requires_naming_scheme_failed(results, request):
258279 assert task_result .outcome == 'FAILED'
259280
260281
282+ @pytest .mark .parametrize ('results' , ('tracer' ,))
261283def test_artifact_contains_requires_naming_scheme_and_looks_as_expected (
262- tracer ):
263- result = tracer ['dist.python-versions.requires_naming_scheme' ]
284+ results , request ):
285+ results = request .getfixturevalue (results )
286+ result = results ['dist.python-versions.requires_naming_scheme' ]
264287 with open (result .artifact ) as f :
265288 artifact = f .read ()
266289
@@ -281,8 +304,10 @@ def test_artifact_contains_requires_naming_scheme_and_looks_as_expected(
281304 """ ).strip () in artifact .strip ()
282305
283306
284- def test_requires_naming_scheme_contains_python (yum ):
285- result = yum ['dist.python-versions.requires_naming_scheme' ]
307+ @pytest .mark .parametrize ('results' , ('yum' ,))
308+ def test_requires_naming_scheme_contains_python (results , request ):
309+ results = request .getfixturevalue (results )
310+ result = results ['dist.python-versions.requires_naming_scheme' ]
286311 with open (result .artifact ) as f :
287312 artifact = f .read ()
288313
@@ -306,9 +331,11 @@ def test_executables_failed(results, request):
306331 assert task_result .outcome == 'FAILED'
307332
308333
334+ @pytest .mark .parametrize ('results' , ('docutils' ,))
309335def test_artifact_contains_executables_and_looks_as_expected (
310- docutils ):
311- result = docutils ['dist.python-versions.executables' ]
336+ results , request ):
337+ results = request .getfixturevalue (results )
338+ result = results ['dist.python-versions.executables' ]
312339 with open (result .artifact ) as f :
313340 artifact = f .read ()
314341
@@ -352,9 +379,11 @@ def test_unvesioned_shebangs_failed(results, request):
352379 assert result .outcome == 'FAILED'
353380
354381
382+ @pytest .mark .parametrize ('results' , ('tracer' ,))
355383def test_artifact_contains_unversioned_shebangs_and_looks_as_expected (
356- tracer ):
357- result = tracer ['dist.python-versions.unversioned_shebangs' ]
384+ results , request ):
385+ results = request .getfixturevalue (results )
386+ result = results ['dist.python-versions.unversioned_shebangs' ]
358387 with open (result .artifact ) as f :
359388 artifact = f .read ()
360389
@@ -378,9 +407,11 @@ def test_unvesioned_shebangs_mangled_failed(results, request):
378407 assert result .outcome == 'FAILED'
379408
380409
410+ @pytest .mark .parametrize ('results' , ('bucky' ,))
381411def test_artifact_contains_mangled_unversioned_shebangs_and_looks_as_expected (
382- bucky ):
383- result = bucky ['dist.python-versions.unversioned_shebangs' ]
412+ results , request ):
413+ results = request .getfixturevalue (results )
414+ result = results ['dist.python-versions.unversioned_shebangs' ]
384415 with open (result .artifact ) as f :
385416 artifact = f .read ()
386417
@@ -420,15 +451,17 @@ def test_py3_support_failed(results, request):
420451 assert task_result .outcome == 'FAILED'
421452
422453
454+ @pytest .mark .parametrize ('results' , ('bucky' ,))
423455def test_artifact_contains_py3_support_and_looks_as_expected (
424- bucky ):
456+ results , request ):
425457 """Test that py3_support check fails if the package is mispackaged.
426458
427459 NOTE: The test will start to fail as soon as python-bucky
428460 gets ported to Python 3 and its Bugzilla gets closed.
429461 See https://bugzilla.redhat.com/show_bug.cgi?id=1367012
430462 """
431- result = bucky ['dist.python-versions.py3_support' ]
463+ results = request .getfixturevalue (results )
464+ result = results ['dist.python-versions.py3_support' ]
432465 with open (result .artifact ) as f :
433466 artifact = f .read ()
434467
@@ -459,8 +492,11 @@ def test_python_usage_failed(results, request):
459492 assert task_result .outcome == 'FAILED'
460493
461494
462- def test_artifact_contains_python_usage_and_looks_as_expected (jsonrpc ):
463- result = jsonrpc ['dist.python-versions.python_usage' ]
495+ @pytest .mark .parametrize ('results' , ('jsonrpc' ,))
496+ def test_artifact_contains_python_usage_and_looks_as_expected (results ,
497+ request ):
498+ results = request .getfixturevalue (results )
499+ result = results ['dist.python-versions.python_usage' ]
464500 with open (result .artifact ) as f :
465501 artifact = f .read ()
466502
0 commit comments