From 3ab40bbc2351729c156e803c01d2e768d30a4b9b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 10 May 2016 22:43:12 +0200 Subject: [PATCH] Clear globals correctly for all cmdutils tests TestArgument didn't clear the globals as the fixture was inside TestRegister. This means test_run_vulture failed in funny ways because run_vulture.py generated a whitelist containing "" for commands: tests/unit/scripts/test_run_vulture.py:55: in run return run_vulture.run([str(e.basename) for e in files]) scripts/dev/run_vulture.py:146: in run vult.scavenge(files + [whitelist_file.name]) .tox/py35/lib/python3.5/site-packages/vulture.py:107: in scavenge self.scan(module_string) .tox/py35/lib/python3.5/site-packages/vulture.py:75: in scan node = ast.parse(node_string, filename=self.file) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ source = 'qutebrowser.browser.commands.CommandDispatcher.buffer\nqutebrowser.misc.savemanager.SaveManager.save_command\nqutebro...iidoc.UsageFormatter._get_default_metavar_for_positional\nscripts.dev.src2asciidoc.UsageFormatter._metavar_formatter\n' filename = '/tmp/tmp_ein2umn', mode = 'exec' def parse(source, filename='', mode='exec'): """ Parse the source into an AST node. Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). """ > return compile(source, filename, mode, PyCF_ONLY_AST) E File "/tmp/tmp_ein2umn", line 16 E test_cmdutils.TestArgument.test_wrong_order..fun E ^ E SyntaxError: invalid syntax --- qutebrowser/commands/command.py | 1 + tests/unit/commands/test_cmdutils.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index acec7988e..87566ad38 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -454,6 +454,7 @@ class Command: # Special case for count parameter. self._get_count_arg(param, args, kwargs) continue + # elif arg_info.win_id: elif arg_info.win_id: # Special case for win_id parameter. self._get_win_id_arg(win_id, param, args, kwargs) diff --git a/tests/unit/commands/test_cmdutils.py b/tests/unit/commands/test_cmdutils.py index 961e19d02..04cabfe0a 100644 --- a/tests/unit/commands/test_cmdutils.py +++ b/tests/unit/commands/test_cmdutils.py @@ -24,6 +24,13 @@ import pytest from qutebrowser.commands import cmdutils, cmdexc, argparser, command +@pytest.fixture(autouse=True) +def clear_globals(monkeypatch): + """Clear the cmdutils globals between each test.""" + monkeypatch.setattr(cmdutils, 'cmd_dict', {}) + monkeypatch.setattr(cmdutils, 'aliases', []) + + class TestCheckOverflow: def test_good(self): @@ -81,12 +88,6 @@ class TestRegister: # pylint: disable=unused-variable - @pytest.fixture(autouse=True) - def clear_globals(self, monkeypatch): - """Clear the cmdutils globals between each test.""" - monkeypatch.setattr(cmdutils, 'cmd_dict', {}) - monkeypatch.setattr(cmdutils, 'aliases', []) - def test_simple(self): @cmdutils.register() def fun():