1
- import getpass
2
1
import pathlib
3
2
import shutil
4
- import textwrap
3
+ import typing as t
5
4
6
5
import pytest
7
6
8
7
9
- @pytest .fixture (autouse = True , scope = "session" )
10
- def home_path (tmp_path_factory : pytest .TempPathFactory ):
11
- return tmp_path_factory .mktemp ("home" )
8
+ @pytest .fixture (autouse = True )
9
+ def add_doctest_fixtures (
10
+ request : pytest .FixtureRequest ,
11
+ doctest_namespace : t .Dict [str , t .Any ],
12
+ ) -> None :
13
+ from _pytest .doctest import DoctestItem
12
14
15
+ if isinstance (request ._pyfuncitem , DoctestItem ):
16
+ request .getfixturevalue ("add_doctest_fixtures" )
17
+ request .getfixturevalue ("set_home" )
18
+
19
+
20
+ @pytest .fixture (autouse = True )
21
+ def setup (
22
+ request : pytest .FixtureRequest ,
23
+ gitconfig : pathlib .Path ,
24
+ set_home : pathlib .Path ,
25
+ xdg_config_path : pathlib .Path ,
26
+ ) -> None :
27
+ pass
13
28
14
- @pytest .fixture (autouse = True , scope = "session" )
15
- def user_path (home_path : pathlib .Path ):
16
- p = home_path / getpass .getuser ()
17
- p .mkdir ()
18
- return p
29
+
30
+ @pytest .fixture (autouse = True )
31
+ def cwd_default (monkeypatch : pytest .MonkeyPatch , tmp_path : pathlib .Path ) -> None :
32
+ monkeypatch .chdir (tmp_path )
19
33
20
34
21
35
@pytest .fixture (autouse = True , scope = "session" )
22
- @pytest .mark .usefixtures ("set_user_path " )
36
+ @pytest .mark .usefixtures ("set_home " )
23
37
def xdg_config_path (user_path : pathlib .Path ):
24
38
p = user_path / ".config"
25
39
p .mkdir ()
@@ -38,11 +52,6 @@ def clean():
38
52
return conf_path
39
53
40
54
41
- @pytest .fixture (autouse = True )
42
- def set_user_path (monkeypatch : pytest .MonkeyPatch , user_path : pathlib .Path ):
43
- monkeypatch .setenv ("HOME" , str (user_path ))
44
-
45
-
46
55
@pytest .fixture (autouse = True )
47
56
def set_xdg_config_path (monkeypatch : pytest .MonkeyPatch , xdg_config_path : pathlib .Path ):
48
57
monkeypatch .setenv ("XDG_CONFIG_HOME" , str (xdg_config_path ))
@@ -59,38 +68,3 @@ def clean():
59
68
60
69
request .addfinalizer (clean )
61
70
return dir
62
-
63
-
64
- @pytest .fixture (autouse = True , scope = "session" )
65
- def hgrc (user_path : pathlib .Path ):
66
- hgrc = user_path / ".hgrc"
67
- hgrc .write_text (
68
- textwrap .dedent (
69
- f"""
70
- [ui]
71
- username = vcspull tests <vcspull@git-pull.com>
72
- merge = internal:merge
73
-
74
- [trusted]
75
- users = { getpass .getuser ()}
76
- """
77
- ),
78
- encoding = "utf-8" ,
79
- )
80
- return hgrc
81
-
82
-
83
- @pytest .fixture (autouse = True , scope = "module" )
84
- def gitconfig (user_path : pathlib .Path ):
85
- gitconfig = user_path / ".gitconfig"
86
- gitconfig .write_text (
87
- textwrap .dedent (
88
- f"""
89
- [user]
90
- email = libvcs@git-pull.com
91
- name = { getpass .getuser ()}
92
- """
93
- ),
94
- encoding = "utf-8" ,
95
- )
96
- return gitconfig
0 commit comments