Skip to content

Commit 45d7f5c

Browse files
committed
Rename pytest fixtures.
1 parent e6b576f commit 45d7f5c

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

tests/conftest.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66
import pytest
77

88
@pytest.fixture(scope="function")
9-
def runner(request):
9+
def cli_runner(request):
10+
"""click_ CLI runner to execute click_ commands.
11+
12+
.. _click: https://click.pocoo.org/
13+
"""
1014
return CliRunner()
1115

1216
@pytest.fixture(scope="function")
13-
def isolated_runner(request):
14-
runner = CliRunner()
15-
with runner.isolated_filesystem():
16-
yield runner
17+
def cli_runner_isolated(request):
18+
"""click_ CLI runner that provides an isolated filesystem.
19+
20+
.. _click: https://click.pocoo.org/
21+
"""
22+
cli_runner = CliRunner()
23+
with cli_runner.isolated_filesystem():
24+
yield cli_runner

tests/functional/test_basics.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,26 @@ def get_storage_name_for(cls, section_name):
6060
# @pytest.fixture
6161
# def runner2():
6262
# return CliRunner()
63-
64-
xfail = pytest.mark.xfail
65-
63+
#
6664
# -----------------------------------------------------------------------------
6765
# TEST SUITE
6866
# -----------------------------------------------------------------------------
67+
xfail = pytest.mark.xfail
68+
6969
class TestBasics(object):
70-
def test_without_configfile__uses_defaults_from_cmdline(self, isolated_runner):
70+
def test_without_configfile__uses_defaults_from_cmdline(self, cli_runner):
7171
CONTEXT_SETTINGS = dict(default_map=ConfigFileProcessor1.read_config())
7272
@click.command(context_settings=CONTEXT_SETTINGS)
7373
@click.option("-n", "--name", default="__CMDLINE__")
7474
def hello(name):
7575
click.echo("Hello %s" % name)
7676

7777
assert not os.path.exists("hello.ini")
78-
result = isolated_runner.invoke(hello)
78+
result = cli_runner.invoke(hello)
7979
assert result.exit_code == 0
8080
assert result.output == "Hello __CMDLINE__\n"
8181

82-
def test_with_cmdline_and_configfile__prefers_cmdline(self, isolated_runner):
82+
def test_with_cmdline_and_configfile__prefers_cmdline(self, cli_runner_isolated):
8383
assert ConfigFileProcessor1.config_files[0] == "hello.ini"
8484
CONFIG_FILE_CONTENTS1 = """
8585
[hello]
@@ -95,11 +95,11 @@ def test_with_cmdline_and_configfile__prefers_cmdline(self, isolated_runner):
9595
def hello(name):
9696
click.echo("Hello %s" % name)
9797

98-
result = isolated_runner.invoke(hello, ["--name", "CMDLINE_VALUE"])
98+
result = cli_runner_isolated.invoke(hello, ["--name", "CMDLINE_VALUE"])
9999
assert result.exit_code == 0
100100
assert result.output == "Hello CMDLINE_VALUE\n"
101101

102-
def test_with_configfile1__preferred_over_cmdline_defaults(self, isolated_runner):
102+
def test_with_configfile1__preferred_over_cmdline_defaults(self, cli_runner_isolated):
103103
assert ConfigFileProcessor1.config_files[0] == "hello.ini"
104104
CONFIG_FILE_CONTENTS1 = """
105105
[hello]
@@ -116,11 +116,11 @@ def hello(name):
116116
click.echo("Hello %s" % name)
117117

118118
assert os.path.exists("hello.ini")
119-
result = isolated_runner.invoke(hello)
119+
result = cli_runner_isolated.invoke(hello)
120120
assert result.exit_code == 0
121121
assert result.output == "Hello Alice\n"
122122

123-
def test_with_configfile2__usable_as_alternative(self, isolated_runner):
123+
def test_with_configfile2__usable_as_alternative(self, cli_runner_isolated):
124124
assert ConfigFileProcessor1.config_files[1] == "hello.cfg"
125125
CONFIG_FILE_CONTENTS2 = """
126126
[hello]
@@ -136,11 +136,11 @@ def test_with_configfile2__usable_as_alternative(self, isolated_runner):
136136
def hello(name):
137137
click.echo("Hello %s" % name)
138138

139-
result = isolated_runner.invoke(hello)
139+
result = cli_runner_isolated.invoke(hello)
140140
assert result.exit_code == 0
141141
assert result.output == "Hello Bob\n"
142142

143-
def test_with_configfile12__prefers_configfile1(self, isolated_runner):
143+
def test_with_configfile12__prefers_configfile1(self, cli_runner_isolated):
144144
assert ConfigFileProcessor1.config_files == ["hello.ini", "hello.cfg"]
145145
CONFIG_FILE_CONTENTS1 = """
146146
[hello]
@@ -161,12 +161,11 @@ def test_with_configfile12__prefers_configfile1(self, isolated_runner):
161161
def hello(name):
162162
click.echo("Hello %s" % name)
163163

164-
result = isolated_runner.invoke(hello)
164+
result = cli_runner_isolated.invoke(hello)
165165
assert result.exit_code == 0
166166
assert result.output == "Hello alice\n"
167167

168-
# @xfail
169-
def test_configfile__can_pass_additional_params_in_context(self, isolated_runner):
168+
def test_configfile__can_pass_additional_params_in_context(self, cli_runner_isolated):
170169
assert ConfigFileProcessor1.config_files[0] == "hello.ini"
171170
assert not os.path.exists("hello.cfg")
172171
CONFIG_FILE_CONTENTS = """
@@ -192,7 +191,7 @@ def hello(ctx, name):
192191
click.echo("bar.numbers: %s" % repr(ctx.default_map["bar"]["numbers"]))
193192

194193
assert os.path.exists("hello.ini")
195-
result = isolated_runner.invoke(hello)
194+
result = cli_runner_isolated.invoke(hello)
196195
expected_output = """\
197196
Hello Alice
198197
foo.numbers: [1, 2, 3]

0 commit comments

Comments
 (0)