Skip to content

Commit 849eea5

Browse files
authored
Fix lazy_datadir to copy file in a sub-directory (#100)
Fixes #99
1 parent 870ee42 commit 849eea5

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
pytest-datadir
22
==============
33

4+
UNRELEASED
5+
------------
6+
7+
*UNRELEASED*
8+
9+
- Fixed bug using ``lazy_datadir`` to copy a file using a sub-directory (e.g, ``lazy_datadir / 'subdir' / 'file.txt'``) (`#99 <https://github.com/gabrielcnr/pytest-datadir/issues/99>`__).
10+
411
1.7.0
512
---------
613

src/pytest_datadir/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def joinpath(self, other: str) -> Path:
8585
target = self.tmp_path / other
8686
if original.exists() and not target.exists():
8787
if original.is_file():
88+
target.parent.mkdir(parents=True, exist_ok=True)
8889
shutil.copy(
8990
_win32_longpath(str(original)), _win32_longpath(str(target))
9091
)

tests/test_hello.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,16 @@ def test_lazy_copy(lazy_datadir):
121121
"local_directory",
122122
"new-file.txt",
123123
}
124+
125+
126+
def test_lazy_copy_sub_directory(lazy_datadir):
127+
"""Copy via file by using a sub-directory (#99)."""
128+
# The temporary directory starts empty.
129+
assert {x.name for x in lazy_datadir.tmp_path.iterdir()} == set()
130+
131+
# Lazy copy file in a sub-directory.
132+
fn = lazy_datadir / "local_directory/file.txt"
133+
assert {x.name for x in lazy_datadir.tmp_path.iterdir()} == {
134+
"local_directory",
135+
}
136+
assert fn.read_text() == "local contents"

0 commit comments

Comments
 (0)