/
conftest.py
58 lines (41 loc) · 1.28 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import getpass
import textwrap
import pytest
import rich
from twine import settings
from twine import utils
def pytest_configure(config):
# Disable color codes and wrapping during tests
rich.reconfigure(
no_color=True,
width=500,
)
@pytest.fixture()
def config_file(tmpdir, monkeypatch):
path = tmpdir / ".pypirc"
# Mimic common case of .pypirc in home directory
monkeypatch.setattr(utils, "DEFAULT_CONFIG_FILE", path)
return path
@pytest.fixture
def write_config_file(config_file):
def _write(config):
config_file.write(textwrap.dedent(config))
return config_file
return _write
@pytest.fixture()
def make_settings(write_config_file):
"""Return a factory function for settings.Settings with defaults."""
default_config = """
[pypi]
username:foo
password:bar
"""
def _settings(config=default_config, **settings_kwargs):
config_file = write_config_file(config)
settings_kwargs.setdefault("sign_with", None)
settings_kwargs.setdefault("config_file", config_file)
return settings.Settings(**settings_kwargs)
return _settings
@pytest.fixture
def entered_password(monkeypatch):
monkeypatch.setattr(getpass, "getpass", lambda prompt: "entered pw")