From 3f6ae4e0d0d22f4e3394e74c26f1f4a47905d937 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Sat, 18 Feb 2023 20:48:12 +0100 Subject: [PATCH] Add --no-black flag --- pytest_black.py | 5 ++++- tests/test_black.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pytest_black.py b/pytest_black.py index 23b461f..53e233b 100644 --- a/pytest_black.py +++ b/pytest_black.py @@ -18,11 +18,14 @@ def pytest_addoption(parser): group.addoption( "--black", action="store_true", help="enable format checking with black" ) + group.addoption( + "--no-black", action="store_true", default=False, help="disable running black" + ) def pytest_collect_file(file_path, path, parent): config = parent.config - if config.option.black and path.ext == ".py": + if config.option.black and not config.option.no_black and path.ext == ".py": return BlackFile.from_parent(parent, path=file_path) diff --git a/tests/test_black.py b/tests/test_black.py index 0405169..9e2f715 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -24,6 +24,19 @@ def hello(): result.assert_outcomes(failed=1) +def test_disable(testdir): + """Assert no formatting check when black is disabled + """ + testdir.makepyfile( + """ + def hello(): + print('Hello, world') + """ + ) + result = testdir.runpytest("--black", "--no-black") + result.assert_outcomes(failed=0, passed=0) + + def test_pass(testdir): """Assert test passes when no formatting issues are found """