Skip to content

Commit

Permalink
Check both *.py and *.pyi files
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Weiss Bang committed Oct 21, 2020
1 parent 1d0d34a commit 850e89f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# virtual environments

.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

0 comments on commit 850e89f

Please sign in to comment.