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

Check both *.py and *.pyi files: Fixes #40 #52

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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# virtual environments

.venv/
.venv
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion pytest_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def pytest_addoption(parser):

def pytest_collect_file(path, parent):
config = parent.config
if config.option.black and path.ext == ".py":
if config.option.black and path.ext in [".py", ".pyi"]:
if hasattr(BlackItem, "from_parent"):
return BlackItem.from_parent(parent, fspath=path)
else:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_black.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-

import pytest
from py.path import local
from pytest_black import pytest_collect_file


pytestmark = pytest.mark.usefixtures('black_available')
Expand Down Expand Up @@ -176,3 +178,28 @@ def hello():

out = "\n".join(result.stdout.lines)
assert "PytestUnknownMarkWarning" not in out


def test_gathers_pyi_files(tmpdir, request):
"""Assert that pytest_collect_file handles *.pyi files"""
config = request.session
config.config.option.black = True
assert pytest_collect_file(local("test.pyi"), config) is not None


def test_gathers_py_files(tmpdir, request):
"""Assert that pytest_collect_file handles *.py files"""
config = request.session
config.config.option.black = True
assert pytest_collect_file(local("test.py"), config) is not None


def test_ignores_pyc_files(tmpdir, request):
"""
Assert that pytest_collect_file ignores *.pyc files

Used as an example of a non *.pyi and *.py)
"""
config = request.session
config.config.option.black = True
assert pytest_collect_file(local("test.pyc"), config) is None