@@ -248,6 +248,18 @@ def archive(self, path, include=None, exclude=None):
248248 '\' \" .dat\' ' : FileRecord ('Although practicality beats purity.' ),
249249})
250250
251+
252+ @pytest .fixture
253+ def base_repo (tmpdir , git_env ):
254+ """Basic repository for simple tests."""
255+ repo_path = os .path .join (str (tmpdir ), 'repo' )
256+ repo = Repo (repo_path , git_env )
257+ repo .init ()
258+ repo .add_dir ('.' , base )
259+ repo .commit ('init' )
260+ return repo
261+
262+
251263@pytest .mark .parametrize ('contents' , [
252264 pytest .param (base , id = 'No Ignore' ),
253265 pytest .param (base_quoted , id = 'No Ignore (Quoted)' ),
@@ -327,53 +339,35 @@ def test_repo_dirs_with_trailing_whitespaces(name, tmpdir, git_env):
327339 repo .archive (repo_tar_path )
328340
329341
330- def test_explicitly_included_file (tmpdir , git_env ):
331- repo_path = os .path .join (str (tmpdir ), 'repo' )
332- repo = Repo (repo_path , git_env )
333- repo .init ()
334- repo .add_dir ('.' , base )
335- repo .commit ('init' )
336-
337- file_path = os .path .join (repo_path , 'include' )
342+ def test_explicitly_included_file (base_repo , tmpdir , git_env ):
343+ file_path = os .path .join (base_repo .path , 'include' )
338344 with open (file_path , 'w' ) as f :
339345 f .write ('Hello' )
340346
341347 repo_tar_path = os .path .join (str (tmpdir ), 'repo.tar' )
342- repo .archive (repo_tar_path , include = ['include' ])
348+ base_repo .archive (repo_tar_path , include = ['include' ])
343349 repo_tar = TarFile (repo_tar_path , format = PAX_FORMAT , encoding = 'utf-8' )
344350
345351 repo_tar .getmember ('include' )
346352
347353
348- def test_explicitly_included_dir (tmpdir , git_env ):
349- repo_path = os .path .join (str (tmpdir ), 'repo' )
350- repo = Repo (repo_path , git_env )
351- repo .init ()
352- repo .add_dir ('.' , base )
353- repo .commit ('init' )
354-
355- dir_path = os .path .join (repo_path , 'include_dir' )
354+ def test_explicitly_included_dir (base_repo , tmpdir , git_env ):
355+ dir_path = os .path .join (base_repo .path , 'include_dir' )
356356 makedirs (dir_path )
357357 file_path = os .path .join (dir_path , 'include_file' )
358358 with open (file_path , 'w' ) as f :
359359 f .write ('Hello' )
360360
361361 repo_tar_path = os .path .join (str (tmpdir ), 'repo.tar' )
362- repo .archive (repo_tar_path , include = ['include_dir' ])
362+ base_repo .archive (repo_tar_path , include = ['include_dir' ])
363363 repo_tar = TarFile (repo_tar_path , format = PAX_FORMAT , encoding = 'utf-8' )
364364
365365 repo_tar .getmember ('include_dir/include_file' )
366366
367367
368- def test_explicitly_excluded_file (tmpdir , git_env ):
369- repo_path = os .path .join (str (tmpdir ), 'repo' )
370- repo = Repo (repo_path , git_env )
371- repo .init ()
372- repo .add_dir ('.' , base )
373- repo .commit ('init' )
374-
368+ def test_explicitly_excluded_file (base_repo , tmpdir , git_env ):
375369 repo_tar_path = os .path .join (str (tmpdir ), 'repo.tar' )
376- repo .archive (repo_tar_path , exclude = ['app/__init__.py' ])
370+ base_repo .archive (repo_tar_path , exclude = ['app/__init__.py' ])
377371 repo_tar = TarFile (repo_tar_path , format = PAX_FORMAT , encoding = 'utf-8' )
378372
379373 repo_tar .getmember ('lib/__init__.py' )
@@ -382,15 +376,9 @@ def test_explicitly_excluded_file(tmpdir, git_env):
382376 repo_tar .getmember ('app/__init__.py' )
383377
384378
385- def test_explicitly_excluded_dir (tmpdir , git_env ):
386- repo_path = os .path .join (str (tmpdir ), 'repo' )
387- repo = Repo (repo_path , git_env )
388- repo .init ()
389- repo .add_dir ('.' , base )
390- repo .commit ('init' )
391-
379+ def test_explicitly_excluded_dir (base_repo , tmpdir , git_env ):
392380 repo_tar_path = os .path .join (str (tmpdir ), 'repo.tar' )
393- repo .archive (repo_tar_path , exclude = ['lib' ])
381+ base_repo .archive (repo_tar_path , exclude = ['lib' ])
394382 repo_tar = TarFile (repo_tar_path , format = PAX_FORMAT , encoding = 'utf-8' )
395383
396384 repo_tar .getmember ('app/__init__.py' )
0 commit comments