From 3ef71de5f999d12f0a40cbfb5b4f712448e8ece9 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 8 Jan 2022 16:26:02 -0600 Subject: [PATCH] Tests: adding option to copy file into temp dir. --- tests/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 5c21cd938..0228348a2 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,13 +1,23 @@ from contextlib import contextmanager import os +from shutil import copy import tempfile @contextmanager -def cdtemp(): - """Context manager to change to/return from a tmpdir.""" +def cdtemp(files=None): + """Context manager to change to/return from a tmpdir. + + Parameters + ---------- + files : Iterable of str or Path-like + Set of files to copy into the temporary directory + """ with tempfile.TemporaryDirectory() as tmpdir: cwd = os.getcwd() + if files: + for file in files: + copy(file, tmpdir, follow_symlinks=True) try: os.chdir(tmpdir) yield