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 "<locals>" 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='<unknown>', 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.<locals>.fun
    E                                                       ^
    E       SyntaxError: invalid syntax
This commit is contained in:
Florian Bruhin 2016-05-10 22:43:12 +02:00
parent 1611562271
commit 3ab40bbc23
2 changed files with 8 additions and 6 deletions

View File

@ -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)

View File

@ -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():