-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathconftest.py
More file actions
81 lines (57 loc) · 2.12 KB
/
conftest.py
File metadata and controls
81 lines (57 loc) · 2.12 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import click.testing
import pytest
from ...core.api.init import initialise_api
from ...core.api.repos import create_repo, delete_repo
from .utils import random_str
def _get_env_var_or_skip(key):
"""Return the environment variable value if set, otherwise skip the test."""
value = os.environ.get(key)
if not value:
pytest.skip("%s not provided" % key)
return value
@pytest.fixture()
def runner():
"""Return a CliRunner with which to run Commands."""
return click.testing.CliRunner(mix_stderr=False)
@pytest.fixture()
def username():
"""Return the PYTEST_CLOUDSMITH_USERNAME value."""
return _get_env_var_or_skip("PYTEST_CLOUDSMITH_USERNAME")
@pytest.fixture()
def password():
"""Return the PYTEST_CLOUDSMITH_PASSWORD value."""
return _get_env_var_or_skip("PYTEST_CLOUDSMITH_PASSWORD")
@pytest.fixture()
def api_key():
"""Return the PYTEST_CLOUDSMITH_API_KEY value."""
return _get_env_var_or_skip("PYTEST_CLOUDSMITH_API_KEY")
@pytest.fixture()
def organization():
"""Return the PYTEST_CLOUDSMITH_ORGANIZATION value.
This is the name of the organization to use for pytest runs.
"""
return _get_env_var_or_skip("PYTEST_CLOUDSMITH_ORGANIZATION")
@pytest.fixture()
def tmp_repository(organization, api_host, api_key):
"""Yield a temporary repository."""
initialise_api(host=api_host, key=api_key)
repo_data = create_repo(organization, {"name": random_str()})
yield repo_data
delete_repo(organization, repo_data["slug"])
@pytest.fixture()
def api_host():
"""Return the PYTEST_CLOUDSMITH_API_HOST value."""
return _get_env_var_or_skip("PYTEST_CLOUDSMITH_API_HOST")
@pytest.fixture()
def set_api_host_env_var(api_host):
"""Set the CLOUDSMITH_API_HOST environment variable."""
os.environ["CLOUDSMITH_API_HOST"] = api_host
@pytest.fixture()
def set_api_key_env_var(api_key):
"""Set the CLOUDSMITH_API_KEY environment variable."""
os.environ["CLOUDSMITH_API_KEY"] = api_key
@pytest.fixture()
def set_no_warn_env_var():
"""Set the CLOUDSMITH_API_KEY environment variable."""
os.environ["CLOUDSMITH_CLI_NO_WARN"] = "True"