From f4714a93000ab208508953b9610042fd4569d538 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 4 Jan 2022 10:27:51 +0100 Subject: Use flake8-pytest-style --- .flake8 | 13 +++++++++++-- misc/requirements/requirements-flake8.txt | 2 ++ misc/requirements/requirements-flake8.txt-raw | 1 + scripts/dev/recompile_requirements.py | 2 ++ tests/end2end/test_insert_mode.py | 2 +- tests/helpers/fixtures.py | 2 +- tests/unit/browser/test_caret.py | 2 +- tests/unit/browser/test_history.py | 2 +- tests/unit/browser/test_inspector.py | 3 ++- tests/unit/browser/webkit/test_webkitelem.py | 2 -- tests/unit/completion/test_completionwidget.py | 4 ++-- tests/unit/completion/test_models.py | 4 ++-- tests/unit/config/test_configcommands.py | 4 ++-- tests/unit/config/test_configfiles.py | 1 - tests/unit/config/test_configtypes.py | 1 - tests/unit/config/test_configutils.py | 2 -- tests/unit/config/test_qtargs.py | 2 -- tests/unit/config/test_websettings.py | 2 +- tests/unit/misc/test_guiprocess.py | 4 ++-- tests/unit/misc/test_miscwidgets.py | 2 +- tests/unit/utils/test_log.py | 2 +- tests/unit/utils/test_qtutils.py | 5 ++--- tests/unit/utils/test_resources.py | 2 +- 23 files changed, 36 insertions(+), 30 deletions(-) diff --git a/.flake8 b/.flake8 index 5cfa2e76c..9110dc54c 100644 --- a/.flake8 +++ b/.flake8 @@ -41,6 +41,9 @@ exclude = .*,__pycache__,resources.py # W503: like break before binary operator # W504: line break after binary operator # FI15: __future__ import "generator_stop" missing +# PT004: fixture '{name}' does not return anything, add leading underscore +# PT011: pytest.raises(ValueError) is too broad, set the match parameter or use a more specific exception +# PT012: pytest.raises() block should contain a single simple statement ignore = B001,B008,B305, E128,E226,E265,E501,E402,E266,E722,E731, @@ -49,8 +52,11 @@ ignore = P101,P102,P103, D102,D103,D106,D107,D104,D105,D209,D211,D401,D402,D403,D412,D413, A003, - W503, W504 - FI15 + W503, W504, + FI15, + PT004, + PT011, + PT012 min-version = 3.6.1 max-complexity = 12 per-file-ignores = @@ -62,3 +68,6 @@ per-file-ignores = copyright-check = True copyright-regexp = # Copyright [\d-]+ .* copyright-min-file-size = 110 +pytest-fixture-no-parentheses = True +pytest-mark-no-parentheses = True +pytest-parametrize-names-type = csv diff --git a/misc/requirements/requirements-flake8.txt b/misc/requirements/requirements-flake8.txt index 9ae455f2d..2f13b4733 100644 --- a/misc/requirements/requirements-flake8.txt +++ b/misc/requirements/requirements-flake8.txt @@ -11,7 +11,9 @@ flake8-deprecated==1.3 flake8-docstrings==1.6.0 flake8-future-import==0.4.6 flake8-mock==0.3 +flake8-plugin-utils==1.3.2 flake8-polyfill==1.0.2 +flake8-pytest-style==1.6.0 flake8-string-format==0.3.0 flake8-tidy-imports==4.5.0 flake8-tuple==0.4.1 diff --git a/misc/requirements/requirements-flake8.txt-raw b/misc/requirements/requirements-flake8.txt-raw index 1bdca6974..59908897c 100644 --- a/misc/requirements/requirements-flake8.txt-raw +++ b/misc/requirements/requirements-flake8.txt-raw @@ -11,6 +11,7 @@ flake8-mock flake8-string-format flake8-tidy-imports flake8-tuple +flake8-pytest-style pep8-naming pydocstyle pyflakes diff --git a/scripts/dev/recompile_requirements.py b/scripts/dev/recompile_requirements.py index 65f7250b3..dc56380bf 100644 --- a/scripts/dev/recompile_requirements.py +++ b/scripts/dev/recompile_requirements.py @@ -95,6 +95,8 @@ CHANGELOG_URLS = { 'flake8-mock': 'https://github.com/aleGpereira/flake8-mock#changes', 'flake8-polyfill': 'https://gitlab.com/pycqa/flake8-polyfill/-/blob/master/CHANGELOG.rst', 'flake8-string-format': 'https://github.com/xZise/flake8-string-format#changes', + 'flake8-plugin-utils': 'https://github.com/afonasev/flake8-plugin-utils#change-log', + 'flake8-pytest-style': 'https://github.com/m-burst/flake8-pytest-style#change-log', 'pep8-naming': 'https://github.com/PyCQA/pep8-naming/blob/master/CHANGELOG.rst', 'pycodestyle': 'https://github.com/PyCQA/pycodestyle/blob/master/CHANGES.txt', 'pyflakes': 'https://github.com/PyCQA/pyflakes/blob/master/NEWS.rst', diff --git a/tests/end2end/test_insert_mode.py b/tests/end2end/test_insert_mode.py index e829f25a6..47e481b3d 100644 --- a/tests/end2end/test_insert_mode.py +++ b/tests/end2end/test_insert_mode.py @@ -22,7 +22,7 @@ import pytest -@pytest.mark.parametrize(['file_name', 'elem_id', 'source', 'input_text'], [ +@pytest.mark.parametrize('file_name, elem_id, source, input_text', [ ('textarea.html', 'qute-textarea', 'clipboard', 'qutebrowser'), ('textarea.html', 'qute-textarea', 'keypress', 'superqutebrowser'), ('input.html', 'qute-input', 'clipboard', 'amazingqutebrowser'), diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index dd902eb7d..cc362290f 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -632,7 +632,7 @@ def redirect_webengine_data(data_tmpdir, monkeypatch): monkeypatch.setenv('HOME', str(data_tmpdir)) -@pytest.fixture() +@pytest.fixture def short_tmpdir(): """A short temporary directory for a XDG_RUNTIME_DIR.""" with tempfile.TemporaryDirectory() as tdir: diff --git a/tests/unit/browser/test_caret.py b/tests/unit/browser/test_caret.py index 288471ea0..86014040d 100644 --- a/tests/unit/browser/test_caret.py +++ b/tests/unit/browser/test_caret.py @@ -70,7 +70,7 @@ class Selection: self._qtbot.wait(50) - assert False, 'Failed to get selection!' + pytest.fail('Failed to get selection!') def check_multiline(self, expected, *, strip=False): self.check(textwrap.dedent(expected).strip(), strip=strip) diff --git a/tests/unit/browser/test_history.py b/tests/unit/browser/test_history.py index 7906d385c..51a9effb8 100644 --- a/tests/unit/browser/test_history.py +++ b/tests/unit/browser/test_history.py @@ -141,7 +141,7 @@ class TestDelete: class TestAdd: - @pytest.fixture() + @pytest.fixture def mock_time(self, mocker): m = mocker.patch('qutebrowser.browser.history.time') m.time.return_value = 12345 diff --git a/tests/unit/browser/test_inspector.py b/tests/unit/browser/test_inspector.py index f7f532050..61ac9510d 100644 --- a/tests/unit/browser/test_inspector.py +++ b/tests/unit/browser/test_inspector.py @@ -151,4 +151,5 @@ def test_detach_after_toggling(hidden_again, needs_recreate, else: with qtbot.assert_not_emitted(fake_inspector.recreate): fake_inspector.set_position(inspector.Position.window) - assert fake_inspector.isVisible() and fake_inspector.isWindow() + assert fake_inspector.isVisible() + assert fake_inspector.isWindow() diff --git a/tests/unit/browser/webkit/test_webkitelem.py b/tests/unit/browser/webkit/test_webkitelem.py index 3ccf573ff..f7cc3e8c2 100644 --- a/tests/unit/browser/webkit/test_webkitelem.py +++ b/tests/unit/browser/webkit/test_webkitelem.py @@ -866,8 +866,6 @@ class TestIsEditable: @pytest.mark.parametrize('setting, tagname, attributes, editable', [ (True, 'embed', {}, True), - (True, 'embed', {}, True), - (False, 'applet', {}, False), (False, 'applet', {}, False), (True, 'object', {'type': 'application/foo'}, True), (False, 'object', {'type': 'application/foo'}, False), diff --git a/tests/unit/completion/test_completionwidget.py b/tests/unit/completion/test_completionwidget.py index 9a1bc99dd..074228332 100644 --- a/tests/unit/completion/test_completionwidget.py +++ b/tests/unit/completion/test_completionwidget.py @@ -37,13 +37,13 @@ def completionview(qtbot, status_command_stub, config_stub, win_registry, mocker.patch('qutebrowser.completion.completer.Completer', autospec=True) mocker.patch( 'qutebrowser.completion.completiondelegate.CompletionItemDelegate', - new=lambda *_: None) + return_value=None) view = completionwidget.CompletionView(cmd=status_command_stub, win_id=0) qtbot.add_widget(view) return view -@pytest.fixture() +@pytest.fixture def model(): return completionmodel.CompletionModel() diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index c20fe293c..9e6743083 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -76,7 +76,7 @@ def _check_completions(model, expected): assert sum(model.column_widths) == 100 -@pytest.fixture() +@pytest.fixture def cmdutils_stub(monkeypatch, stubs): """Patch the cmdutils module to provide fake commands.""" return monkeypatch.setattr(objects, 'commands', { @@ -93,7 +93,7 @@ def cmdutils_stub(monkeypatch, stubs): }) -@pytest.fixture() +@pytest.fixture def configdata_stub(config_stub, monkeypatch, configdata_init): """Patch the configdata module to provide fake data.""" monkeypatch.setattr(configdata, 'DATA', collections.OrderedDict([ diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index 384eb92ab..6dd09cee3 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -27,7 +27,7 @@ from PyQt5.QtCore import QUrl from qutebrowser.config import configcommands from qutebrowser.api import cmdutils -from qutebrowser.utils import usertypes, urlmatch +from qutebrowser.utils import usertypes, urlmatch, utils from qutebrowser.keyinput import keyutils from qutebrowser.misc import objects @@ -529,7 +529,7 @@ class TestSource: pyfile = config_tmpdir / 'sourced.py' arg = 'sourced.py' else: - assert False, location + raise utils.Unreachable(location) pyfile.write_text('\n'.join(['config.load_autoconfig(False)', 'c.content.javascript.enabled = False']), diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index fe51f896f..760992e15 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -1481,7 +1481,6 @@ class TestConfigPyWriter: def init_patch(qapp, fake_save_manager, config_tmpdir, data_tmpdir, config_stub, monkeypatch): monkeypatch.setattr(configfiles, 'state', None) - yield def test_init(init_patch, config_tmpdir): diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 66b152937..ef3007f71 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -1876,7 +1876,6 @@ class TestShellCommand: @pytest.mark.parametrize('kwargs, val', [ ({'placeholder': True}, '[foo, bar]'), ({'placeholder': True}, '[foo, "{", "}", bar'), - ({'placeholder': True}, '[foo, bar]'), ({'placeholder': True}, '[foo, "{fi", "le}", bar'), # Like valid ones but with wrong placeholder diff --git a/tests/unit/config/test_configutils.py b/tests/unit/config/test_configutils.py index 89db342b7..3fc5cd561 100644 --- a/tests/unit/config/test_configutils.py +++ b/tests/unit/config/test_configutils.py @@ -318,13 +318,11 @@ class TestFontFamilies: @pytest.mark.parametrize('families, quote, expected', [ (['family'], True, 'family'), (['family1', 'family2'], True, 'family1, family2'), - (['family'], True, 'family'), (['space family', 'alien'], True, '"space family", alien'), (['comma,family', 'period'], True, '"comma,family", period'), (['family'], False, 'family'), (['family1', 'family2'], False, 'family1, family2'), - (['family'], False, 'family'), (['space family', 'alien'], False, 'space family, alien'), (['comma,family', 'period'], False, 'comma,family, period'), ]) diff --git a/tests/unit/config/test_qtargs.py b/tests/unit/config/test_qtargs.py index 4c31c5b07..d95382624 100644 --- a/tests/unit/config/test_qtargs.py +++ b/tests/unit/config/test_qtargs.py @@ -324,7 +324,6 @@ class TestWebEngineArgs: ("light", "5.15.0", False), ("light", "5.15.1", False), ("light", "5.15.2", False), - ("light", "5.15.2", False), ("light", "5.15.3", False), ("light", "6.0.0", False), @@ -333,7 +332,6 @@ class TestWebEngineArgs: ("auto", "5.15.0", False), ("auto", "5.15.1", False), ("auto", "5.15.2", False), - ("auto", "5.15.2", False), ("auto", "5.15.3", False), ("auto", "6.0.0", False), ]) diff --git a/tests/unit/config/test_websettings.py b/tests/unit/config/test_websettings.py index 7601c7c24..f42563727 100644 --- a/tests/unit/config/test_websettings.py +++ b/tests/unit/config/test_websettings.py @@ -24,7 +24,7 @@ from qutebrowser.misc import objects from qutebrowser.utils import usertypes -@pytest.mark.parametrize([ +@pytest.mark.parametrize([ # noqa: PT006 'user_agent', 'os_info', 'webkit_version', 'upstream_browser_key', 'upstream_browser_version', 'qt_key' ], [ diff --git a/tests/unit/misc/test_guiprocess.py b/tests/unit/misc/test_guiprocess.py index faf2006de..c664757fd 100644 --- a/tests/unit/misc/test_guiprocess.py +++ b/tests/unit/misc/test_guiprocess.py @@ -31,7 +31,7 @@ from qutebrowser.api import cmdutils from qutebrowser.qt import sip -@pytest.fixture() +@pytest.fixture def proc(qtbot, caplog): """A fixture providing a GUIProcess and cleaning it up after the test.""" p = guiprocess.GUIProcess('testprocess') @@ -46,7 +46,7 @@ def proc(qtbot, caplog): p._proc.waitForFinished() -@pytest.fixture() +@pytest.fixture def fake_proc(monkeypatch, stubs): """A fixture providing a GUIProcess with a mocked QProcess.""" p = guiprocess.GUIProcess('testprocess') diff --git a/tests/unit/misc/test_miscwidgets.py b/tests/unit/misc/test_miscwidgets.py index 6e1919ec3..3c5c1eef1 100644 --- a/tests/unit/misc/test_miscwidgets.py +++ b/tests/unit/misc/test_miscwidgets.py @@ -38,7 +38,7 @@ class TestCommandLineEdit: cmd_edit.set_prompt(':') qtbot.add_widget(cmd_edit) assert cmd_edit.text() == '' - yield cmd_edit + return cmd_edit def test_position(self, qtbot, cmd_edit): """Test cursor position based on the prompt.""" diff --git a/tests/unit/utils/test_log.py b/tests/unit/utils/test_log.py index 7b0f5293e..9f5a15065 100644 --- a/tests/unit/utils/test_log.py +++ b/tests/unit/utils/test_log.py @@ -348,7 +348,7 @@ class TestHideQtWarning: """Tests for hide_qt_warning/QtWarningFilter.""" - @pytest.fixture() + @pytest.fixture def qt_logger(self): return logging.getLogger('qt-tests') diff --git a/tests/unit/utils/test_qtutils.py b/tests/unit/utils/test_qtutils.py index 6309e46b5..ad9adf032 100644 --- a/tests/unit/utils/test_qtutils.py +++ b/tests/unit/utils/test_qtutils.py @@ -51,8 +51,7 @@ else: test_file = None -@pytest.mark.parametrize(['qversion', 'compiled', 'pyqt', 'version', 'exact', - 'expected'], [ +@pytest.mark.parametrize('qversion, compiled, pyqt, version, exact, expected', [ # equal versions ('5.14.0', None, None, '5.14.0', False, True), ('5.14.0', None, None, '5.14.0', True, True), # exact=True @@ -741,7 +740,7 @@ class TestPyQIODevice: with pytest.raises(io.UnsupportedOperation): pyqiodev.seek(0, whence) - @pytest.mark.flaky() + @pytest.mark.flaky def test_qprocess(self, py_proc): """Test PyQIODevice with a QProcess which is non-sequential. diff --git a/tests/unit/utils/test_resources.py b/tests/unit/utils/test_resources.py index 738fadd37..6a11ff588 100644 --- a/tests/unit/utils/test_resources.py +++ b/tests/unit/utils/test_resources.py @@ -65,7 +65,7 @@ class TestReadFile: 'qutebrowser/html/unrelatedhtml', ] - yield zipfile.Path(zip_path) / 'qutebrowser' + return zipfile.Path(zip_path) / 'qutebrowser' @pytest.fixture(params=['pathlib', 'zipfile']) def resource_root(self, request): -- cgit v1.2.3-54-g00ecf