File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ from pathlib import Path
2
+ from shutil import copytree
3
+
4
+ import pytest
5
+
6
+ try :
7
+ from contextlib import chdir as _chdir
8
+ except ImportError : # PY310
9
+ import os
10
+ from contextlib import contextmanager
11
+
12
+ @contextmanager # type: ignore
13
+ def _chdir (path ):
14
+ cwd = os .getcwd ()
15
+ os .chdir (path )
16
+ try :
17
+ yield
18
+ finally :
19
+ os .chdir (cwd )
20
+
21
+
22
+ @pytest .fixture (scope = 'module' )
23
+ def data_dir ():
24
+ return Path (__file__ ).parent / 'tests' / 'data'
25
+
26
+
27
+ @pytest .fixture (autouse = True )
28
+ def _docdir (request , tmp_path ):
29
+ # Trigger ONLY for the doctests.
30
+ doctest_plugin = request .config .pluginmanager .getplugin ('doctest' )
31
+ if isinstance (request .node , doctest_plugin .DoctestItem ):
32
+ copytree (Path (__file__ ).parent / 'tests' / 'data' , tmp_path , dirs_exist_ok = True )
33
+
34
+ # Chdir only for the duration of the test.
35
+ with _chdir (tmp_path ):
36
+ yield
37
+
38
+ else :
39
+ # For normal tests, we have to yield, since this is a yield-fixture.
40
+ yield
You can’t perform that action at this time.
0 commit comments