Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: refactor to resolve deprecated pytest features #903

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CLIParsing:
High level parsing tests
"""

def setup(self):
def setup_method(self):
@task(positional=[], iterable=["my_list"], incrementable=["verbose"])
def my_task(
c,
Expand Down
20 changes: 10 additions & 10 deletions tests/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def task3(c):
submeh = Collection("submeh", task3)
return Collection("meh", task1, task2, submeh)

def setup(self):
def setup_method(self):
self.c = self._meh()

def repr_(self):
Expand Down Expand Up @@ -148,11 +148,11 @@ def foo(c):
assert not Collection(foo=Collection())

class from_module:
def setup(self):
def setup_method(self):
self.c = Collection.from_module(load("integration"))

class parameters:
def setup(self):
def setup_method(self):
self.mod = load("integration")
self.from_module = Collection.from_module

Expand Down Expand Up @@ -232,7 +232,7 @@ def returns_unique_Collection_objects_for_same_input_module(self):
assert c3 is not c4

class explicit_root_ns:
def setup(self):
def setup_method(self):
mod = load("explicit_root")
mod.ns.configure(
{
Expand Down Expand Up @@ -278,7 +278,7 @@ def docstring_still_copied_from_module(self):
assert self.changed.__doc__.strip() == expected

class add_task:
def setup(self):
def setup_method(self):
self.c = Collection()

def associates_given_callable_with_given_name(self):
Expand Down Expand Up @@ -350,7 +350,7 @@ def biz(c):
assert self.c[x] is self.c["biz"]

class add_collection:
def setup(self):
def setup_method(self):
self.c = Collection()

def adds_collection_as_subcollection_of_self(self):
Expand Down Expand Up @@ -394,7 +394,7 @@ def raises_ValueError_on_multiple_defaults(self):
class getitem:
"__getitem__"

def setup(self):
def setup_method(self):
self.c = Collection()

def finds_own_tasks_by_name(self):
Expand Down Expand Up @@ -447,7 +447,7 @@ def ValueError_for_empty_subcol_task_name_and_no_default(self):
self.c["whatever"]

class to_contexts:
def setup(self):
def setup_method(self):
@task
def mytask(c, text, boolean=False, number=5):
print(text)
Expand Down Expand Up @@ -598,7 +598,7 @@ def exposes_aliases(self):
assert "mytask27" in self.aliases

class task_names:
def setup(self):
def setup_method(self):
self.c = Collection.from_module(load("explicit_root"))

def returns_all_task_names_including_subtasks(self):
Expand All @@ -614,7 +614,7 @@ def includes_aliases_and_defaults_as_values(self):
class configuration:
"Configuration methods"

def setup(self):
def setup_method(self):
self.root = Collection()
self.task = Task(_func, name="task")

Expand Down
4 changes: 2 additions & 2 deletions tests/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class CompletionScriptPrinter:
Printing the completion script
"""

def setup(self):
def setup_method(self):
self.prev_cwd = os.getcwd()
# Chdir to system root to (hopefully) avoid any tasks.py. This will
# prove that --print-completion-script works w/o nearby tasks.
os.chdir(ROOT)

def teardown(self):
def teardown_method(self):
os.chdir(self.prev_cwd)

def only_accepts_certain_shells(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# TODO: rename
class ExceptionHandlingThread_:
class via_target:
def setup(self):
def setup_method(self):
def worker(q):
q.put(7)

Expand Down Expand Up @@ -48,7 +48,7 @@ def exhibits_is_dead_flag(self):
assert not t.is_dead

class via_subclassing:
def setup(self):
def setup_method(self):
class MyThread(EHThread):
def __init__(self, *args, **kwargs):
self.queue = kwargs.pop("queue")
Expand Down
6 changes: 3 additions & 3 deletions tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def sudo(self):
class configuration_proxy:
"Dict-like proxy for self.config"

def setup(self):
def setup_method(self):
config = Config(defaults={"foo": "bar", "biz": {"baz": "boz"}})
self.c = Context(config=config)

Expand Down Expand Up @@ -133,7 +133,7 @@ def update(self):
assert self.c.biz.otherbaz == "otherboz"

class cwd:
def setup(self):
def setup_method(self):
self.c = Context()

def simple(self):
Expand Down Expand Up @@ -401,7 +401,7 @@ def sudo_password_kwarg_wins_over_config(self):
self._expect_responses(expected, config=config, kwargs=kwargs)

class auto_response_merges_with_other_responses:
def setup(self):
def setup_method(self):
class DummyWatcher(StreamWatcher):
def submit(self, stream):
pass
Expand Down
2 changes: 1 addition & 1 deletion tests/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class Executor_:
def setup(self):
def setup_method(self):
self.task1 = Task(Mock(return_value=7))
self.task2 = Task(Mock(return_value=10), pre=[self.task1])
self.task3 = Task(Mock(), pre=[self.task1])
Expand Down
2 changes: 1 addition & 1 deletion tests/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def find(self, name):


class FilesystemLoader_:
def setup(self):
def setup_method(self):
self.loader = FSLoader(start=support)

def discovery_start_point_defaults_to_cwd(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/parser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def may_give_arg_list_at_init_time(self):
# tests within 'add_arg'. Some of this behavior is technically driven by
# add_arg.
class args:
def setup(self):
def setup_method(self):
self.c = Context(
args=(
Argument("foo"),
Expand Down Expand Up @@ -56,7 +56,7 @@ def argument_attr_names_appear_in_args_but_not_flags(self):
assert "wat" not in self.c.flags

class add_arg:
def setup(self):
def setup_method(self):
self.c = Context()

def can_take_Argument_instance(self):
Expand Down Expand Up @@ -134,7 +134,7 @@ def positional_arg_modifications_affect_args_copy(self):
class deepcopy:
"__deepcopy__"

def setup(self):
def setup_method(self):
self.arg = Argument("--boolean")
self.orig = Context(
name="mytask", args=(self.arg,), aliases=("othername",)
Expand All @@ -157,7 +157,7 @@ def modifications_to_copied_arguments_do_not_touch_originals(self):
assert not self.arg.value

class help_for:
def setup(self):
def setup_method(self):
# Normal, non-task/collection related Context
self.vanilla = Context(
args=(Argument("foo"), Argument("bar", help="bar the baz"))
Expand Down
6 changes: 3 additions & 3 deletions tests/parser_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def clones_noninitial_contexts(self):
assert a2.value == "val"

class parsing_errors:
def setup(self):
def setup_method(self):
self.p = Parser([Context(name="foo", args=[Argument("bar")])])

def missing_flag_values_raise_ParseError(self):
Expand Down Expand Up @@ -280,7 +280,7 @@ def handles_multiple_boolean_flags_per_context(self):
assert a.bar.value is True

class optional_arg_values:
def setup(self):
def setup_method(self):
self.parser = self._parser()

def _parser(self, arguments=None):
Expand Down Expand Up @@ -525,7 +525,7 @@ def other_tokens_afterwards_raise_parse_errors(self):
class ParseResult_:
"ParseResult"

def setup(self):
def setup_method(self):
self.context = Context(
"mytask", args=(Argument("foo", kind=str), Argument("bar"))
)
Expand Down
2 changes: 1 addition & 1 deletion tests/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ def invalid_namespaces_exit_with_message(self):
)

class json:
def setup(self):
def setup_method(self):
# Stored expected data as an actual JSON file cuz it's big
# & looks like crap if inlined. Plus by round-tripping it
# we remove the pretty-printing. Win-win?
Expand Down
14 changes: 7 additions & 7 deletions tests/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _expect_platform_shell(shell):
assert shell == "/bin/bash"


def make_tcattrs(cc_is_ints=True, echo=False):
def _make_tcattrs(cc_is_ints=True, echo=False):
# Set up the control character sub-array; it's technically platform
# dependent so we need to be dynamic.
# NOTE: setting this up so we can test both potential values for
Expand Down Expand Up @@ -665,7 +665,7 @@ def similar_to_just_the_result_repr(self):
assert repr(e) == expected.format(_)

class UnexpectedExit_str:
def setup(self):
def setup_method(self):
def lines(prefix):
prefixed = "\n".join(
"{} {}".format(prefix, x) for x in range(1, 26)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ class character_buffered_stdin:
@skip_if_windows
@patch("invoke.terminals.tty")
def setcbreak_called_on_tty_stdins(self, mock_tty, mock_termios):
mock_termios.tcgetattr.return_value = make_tcattrs(echo=True)
mock_termios.tcgetattr.return_value = _make_tcattrs(echo=True)
self._run(_)
mock_tty.setcbreak.assert_called_with(sys.stdin)

Expand Down Expand Up @@ -1269,7 +1269,7 @@ def tty_stdins_have_settings_restored_by_default(
):
# Get already-cbroken attrs since that's an easy way to get the
# right format/layout
attrs = make_tcattrs(echo=True)
attrs = _make_tcattrs(echo=True)
mock_termios.tcgetattr.return_value = attrs
self._run(_)
# Ensure those old settings are being restored
Expand All @@ -1283,7 +1283,7 @@ def tty_stdins_have_settings_restored_on_KeyboardInterrupt(
self, mock_tty, mock_termios
):
# This test is re: GH issue #303
sentinel = make_tcattrs(echo=True)
sentinel = _make_tcattrs(echo=True)
mock_termios.tcgetattr.return_value = sentinel
# Don't actually bubble up the KeyboardInterrupt...
try:
Expand All @@ -1307,7 +1307,7 @@ def setcbreak_not_called_if_terminal_seems_already_cbroken(
# Test both bytes and ints versions of CC values, since docs
# disagree with at least some platforms' realities on that.
for is_ints in (True, False):
mock_termios.tcgetattr.return_value = make_tcattrs(
mock_termios.tcgetattr.return_value = _make_tcattrs(
cc_is_ints=is_ints
)
self._run(_)
Expand Down Expand Up @@ -1752,7 +1752,7 @@ def repr_contains_useful_info(self):
assert repr(Result(command="foo")) == "<Result cmd='foo' exited=0>"

class tail:
def setup(self):
def setup_method(self):
self.sample = "\n".join(str(x) for x in range(25))

def returns_last_10_lines_of_given_stream_plus_whitespace(self):
Expand Down
10 changes: 5 additions & 5 deletions tests/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _load(self, name):
mod, _ = self.loader.load(name)
return Collection.from_module(mod)

def setup(self):
def setup_method(self):
self.loader = Loader(start=support)
self.vanilla = self._load("decorators")

Expand Down Expand Up @@ -215,7 +215,7 @@ def can_override_name(self):
assert Task(_func, name="foo").name == "foo"

class callability:
def setup(self):
def setup_method(self):
@task
def foo(c):
"My docstring"
Expand Down Expand Up @@ -258,7 +258,7 @@ def wraps_body_name(self):
assert self.task.__name__ == "foo"

class get_arguments:
def setup(self):
def setup_method(self):
@task(positional=["arg_3", "arg1"], optional=["arg1"])
def mytask(c, arg1, arg2=False, arg_3=5):
pass
Expand Down Expand Up @@ -378,7 +378,7 @@ def mytask(c, longer_arg):
assert arg.name == "longer_arg"

class help:
def setup(self):
def setup_method(self):
@task(
help={
"simple": "key",
Expand Down Expand Up @@ -450,7 +450,7 @@ def second(c, shared):


class Call_:
def setup(self):
def setup_method(self):
self.task = Task(Mock(__name__="mytask"))

class init:
Expand Down