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

Add --no-black flag #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion pytest_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
13 changes: 13 additions & 0 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down