forked from pool/python-pytest-black
Compare commits
4 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| c42a183c8a | |||
| 0f442c9d41 | |||
| b3b408b951 | |||
| fe8efa9b63 |
@@ -1,46 +1,239 @@
|
|||||||
From 475cf71aa9de3ededa972ffb36fb47ad79278531 Mon Sep 17 00:00:00 2001
|
From edcbcae7d55a992e785c7fc001f9d3880b197ea2 Mon Sep 17 00:00:00 2001
|
||||||
From: Ben Greiner <code@bnavigator.de>
|
From: Frank Harrison <frank@doublethefish.com>
|
||||||
Date: Mon, 15 Mar 2021 11:42:27 +0100
|
Date: Tue, 28 Dec 2021 12:21:00 +0000
|
||||||
Subject: [PATCH] fix pytest.tmpdir.makefile call
|
Subject: [PATCH] fix(tests): Updates pytest fixture and Path uses - no
|
||||||
|
functional change
|
||||||
|
|
||||||
|
Here we update API calls to use the latest reccomended:
|
||||||
|
* all 'testdir' fixtures now use the prefered 'pytester' fixture (the
|
||||||
|
same in all usecases for pytest-black).
|
||||||
|
* all 'Path.write' uses now use the more explicit `Path.write_text' api
|
||||||
|
instead.
|
||||||
|
* we replace `makefile("pyproject.toml", ...` with `makepyprojecttoml(`
|
||||||
|
which is clearly defined just for this usecase.
|
||||||
|
|
||||||
|
There should be no functional change with this patch, except that older
|
||||||
|
python versions are probably no longer supported.
|
||||||
---
|
---
|
||||||
tests/test_black.py | 12 ++++++------
|
tests/test_black.py | 97 ++++++++++++++++++++++-----------------------
|
||||||
1 file changed, 6 insertions(+), 6 deletions(-)
|
1 file changed, 47 insertions(+), 50 deletions(-)
|
||||||
|
|
||||||
diff --git a/tests/test_black.py b/tests/test_black.py
|
diff --git a/tests/test_black.py b/tests/test_black.py
|
||||||
index 0405169..a7a6026 100644
|
index 0405169..29af9c2 100644
|
||||||
--- a/tests/test_black.py
|
--- a/tests/test_black.py
|
||||||
+++ b/tests/test_black.py
|
+++ b/tests/test_black.py
|
||||||
@@ -72,8 +72,8 @@ def test_exclude(testdir):
|
@@ -6,101 +6,99 @@
|
||||||
|
pytestmark = pytest.mark.usefixtures('black_available')
|
||||||
|
|
||||||
|
|
||||||
|
-def test_help_message(testdir):
|
||||||
|
- result = testdir.runpytest("--help")
|
||||||
|
+def test_help_message(pytester):
|
||||||
|
+ result = pytester.runpytest("--help")
|
||||||
|
result.stdout.fnmatch_lines(["*--black*enable format checking with black"])
|
||||||
|
|
||||||
|
|
||||||
|
-def test_fail(testdir):
|
||||||
|
+def test_fail(pytester):
|
||||||
|
"""Assert test fails due to single quoted strings
|
||||||
|
"""
|
||||||
|
- testdir.makepyfile(
|
||||||
|
+ pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def hello():
|
||||||
|
print('Hello, world')
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
- result = testdir.runpytest("--black")
|
||||||
|
+ result = pytester.runpytest("--black")
|
||||||
|
result.assert_outcomes(failed=1)
|
||||||
|
|
||||||
|
|
||||||
|
-def test_pass(testdir):
|
||||||
|
+def test_pass(pytester):
|
||||||
|
"""Assert test passes when no formatting issues are found
|
||||||
|
"""
|
||||||
|
- p = testdir.makepyfile(
|
||||||
|
+ p = pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def hello():
|
||||||
|
print("Hello, world!")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
- # replace trailing newline (stripped by testdir.makepyfile)
|
||||||
|
- p = p.write(p.read() + "\n")
|
||||||
|
+ # replace trailing newline (stripped by pytester.makepyfile)
|
||||||
|
+ p = p.write_text(p.read_text() + "\n")
|
||||||
|
|
||||||
|
- result = testdir.runpytest("--black")
|
||||||
|
+ result = pytester.runpytest("--black")
|
||||||
|
result.assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
|
||||||
|
-def test_mtime_cache(testdir):
|
||||||
|
+def test_mtime_cache(pytester):
|
||||||
|
"""Assert test is skipped when file hasn't changed
|
||||||
|
"""
|
||||||
|
- p = testdir.makepyfile(
|
||||||
|
+ p = pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def hello():
|
||||||
|
print("Hello, world!")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
- # replace trailing newline (stripped by testdir.makepyfile)
|
||||||
|
- contents = p.read() + "\n"
|
||||||
|
- p.write(contents)
|
||||||
|
+ # replace trailing newline (stripped by pytester.makepyfile)
|
||||||
|
+ contents = p.read_text() + "\n"
|
||||||
|
+ p.write_text(contents)
|
||||||
|
|
||||||
|
# Test once to populate the cache
|
||||||
|
- result = testdir.runpytest("--black")
|
||||||
|
+ result = pytester.runpytest("--black")
|
||||||
|
result.assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
# Run it again, it should be skipped
|
||||||
|
- result = testdir.runpytest("--black", "-rs")
|
||||||
|
+ result = pytester.runpytest("--black", "-rs")
|
||||||
|
result.assert_outcomes(skipped=1)
|
||||||
|
result.stdout.fnmatch_lines(["SKIP*previously passed black format checks"])
|
||||||
|
|
||||||
|
# Update the file and test again.
|
||||||
|
- p.write(contents)
|
||||||
|
- result = testdir.runpytest("--black")
|
||||||
|
+ p.write_text(contents)
|
||||||
|
+ result = pytester.runpytest("--black")
|
||||||
|
result.assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
|
||||||
|
-def test_exclude(testdir):
|
||||||
|
+def test_exclude(pytester):
|
||||||
"""Assert test is skipped if path is excluded even if also included
|
"""Assert test is skipped if path is excluded even if also included
|
||||||
"""
|
"""
|
||||||
testdir.makefile(
|
- testdir.makefile(
|
||||||
- "pyproject.toml",
|
- "pyproject.toml",
|
||||||
- """
|
+ pytester.makepyprojecttoml(
|
||||||
+ ".toml",
|
"""
|
||||||
+ pyproject = """
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
include = 'test_exclude.py'
|
include = 'test_exclude.py'
|
||||||
exclude = '.*'
|
exclude = '.*'
|
||||||
@@ -100,8 +100,8 @@ def test_exclude_folder(testdir):
|
""",
|
||||||
|
)
|
||||||
|
- p = testdir.makepyfile(
|
||||||
|
+ p = pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def hello():
|
||||||
|
print("Hello, world!")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
- # replace trailing newline (stripped by testdir.makepyfile)
|
||||||
|
- p = p.write(p.read() + "\n")
|
||||||
|
+ # replace trailing newline (stripped by pytester.makepyfile)
|
||||||
|
+ p = p.write_text(p.read_text() + "\n")
|
||||||
|
|
||||||
|
# Rename pyproject.toml ¯\_(ツ)_/¯
|
||||||
|
- testdir.run("mv", "test_exclude.pyproject.toml", "pyproject.toml")
|
||||||
|
+ pytester.run("mv", "test_exclude.pyproject.toml", "pyproject.toml")
|
||||||
|
|
||||||
|
- result = testdir.runpytest("--black")
|
||||||
|
+ result = pytester.runpytest("--black")
|
||||||
|
result.assert_outcomes(skipped=1, passed=0)
|
||||||
|
|
||||||
|
|
||||||
|
-def test_exclude_folder(testdir):
|
||||||
|
+def test_exclude_folder(pytester):
|
||||||
"""Assert test is skipped for files in a folder
|
"""Assert test is skipped for files in a folder
|
||||||
"""
|
"""
|
||||||
testdir.makefile(
|
- testdir.makefile(
|
||||||
- "pyproject.toml",
|
- "pyproject.toml",
|
||||||
- """
|
+ pytester.makepyprojecttoml(
|
||||||
+ ".toml",
|
"""
|
||||||
+ pyproject = """
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
exclude = '''
|
exclude = '''
|
||||||
(
|
@@ -113,65 +111,64 @@ def test_exclude_folder(testdir):
|
||||||
@@ -137,8 +137,8 @@ def test_include(testdir):
|
'''
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
- p = testdir.makepyfile(
|
||||||
|
+ p = pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def hello():
|
||||||
|
print("Hello, world!")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
- # replace trailing newline (stripped by testdir.makepyfile)
|
||||||
|
- p = p.write(p.read() + "\n")
|
||||||
|
+ # replace trailing newline (stripped by pytester.makepyfile)
|
||||||
|
+ p = p.write_text(p.read_text() + "\n")
|
||||||
|
|
||||||
|
# Move file into folder that should be excluded
|
||||||
|
- ignore_folder = testdir.mkdir("ignore_folder")
|
||||||
|
- testdir.run("mv", "test_exclude_folder.py", ignore_folder)
|
||||||
|
+ ignore_folder = pytester.mkdir("ignore_folder")
|
||||||
|
+ pytester.run("mv", "test_exclude_folder.py", ignore_folder)
|
||||||
|
|
||||||
|
# Rename pyproject.toml ¯\_(ツ)_/¯
|
||||||
|
- testdir.run("mv", "test_exclude_folder.pyproject.toml", "pyproject.toml")
|
||||||
|
+ pytester.run("mv", "test_exclude_folder.pyproject.toml", "pyproject.toml")
|
||||||
|
|
||||||
|
- result = testdir.runpytest("--black")
|
||||||
|
+ result = pytester.runpytest("--black")
|
||||||
|
result.assert_outcomes(skipped=1, passed=0)
|
||||||
|
|
||||||
|
|
||||||
|
-def test_include(testdir):
|
||||||
|
+def test_include(pytester):
|
||||||
"""Assert test is not skipped if path is included but not excluded
|
"""Assert test is not skipped if path is included but not excluded
|
||||||
"""
|
"""
|
||||||
testdir.makefile(
|
- testdir.makefile(
|
||||||
- "pyproject.toml",
|
- "pyproject.toml",
|
||||||
- """
|
+ pytester.makepyprojecttoml(
|
||||||
+ ".toml",
|
"""
|
||||||
+ pyproject = """
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
include = 'test_include'
|
include = 'test_include'
|
||||||
""",
|
""",
|
||||||
|
)
|
||||||
|
- p = testdir.makepyfile(
|
||||||
|
+ p = pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def hello():
|
||||||
|
print("Hello, world!")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
- # replace trailing newline (stripped by testdir.makepyfile)
|
||||||
|
- p = p.write(p.read() + "\n")
|
||||||
|
+ # replace trailing newline (stripped by pytester.makepyfile)
|
||||||
|
+ p = p.write_text(p.read_text() + "\n")
|
||||||
|
|
||||||
|
# Rename pyproject.toml ¯\_(ツ)_/¯
|
||||||
|
- testdir.run("mv", "test_include.pyproject.toml", "pyproject.toml")
|
||||||
|
+ pytester.run("mv", "test_include.pyproject.toml", "pyproject.toml")
|
||||||
|
|
||||||
|
- result = testdir.runpytest("--black")
|
||||||
|
+ result = pytester.runpytest("--black")
|
||||||
|
result.assert_outcomes(skipped=0, passed=1)
|
||||||
|
|
||||||
|
|
||||||
|
-def test_pytest_deprecation_warning(testdir):
|
||||||
|
+def test_pytest_deprecation_warning(pytester):
|
||||||
|
"""Assert no deprecation warning is raised during test."""
|
||||||
|
- p = testdir.makepyfile(
|
||||||
|
+ p = pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def hello():
|
||||||
|
print("Hello, world!")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
- # replace trailing newline (stripped by testdir.makepyfile)
|
||||||
|
- p = p.write(p.read() + "\n")
|
||||||
|
+ # replace trailing newline (stripped by pytester.makepyfile)
|
||||||
|
+ p = p.write_text(p.read_text() + "\n")
|
||||||
|
|
||||||
|
- result = testdir.runpytest("--black")
|
||||||
|
+ result = pytester.runpytest("--black")
|
||||||
|
result.assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
out = "\n".join(result.stdout.lines)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:1d339b004f764d6cd0f06e690f6dd748df3d62e6fe1a692d6a5500ac2c5b75a5
|
|
||||||
size 6898
|
|
||||||
16
pytest9.patch
Normal file
16
pytest9.patch
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
Index: pytest_black-0.6.0/pytest_black.py
|
||||||
|
===================================================================
|
||||||
|
--- pytest_black-0.6.0.orig/pytest_black.py
|
||||||
|
+++ pytest_black-0.6.0/pytest_black.py
|
||||||
|
@@ -20,9 +20,9 @@ def pytest_addoption(parser):
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
-def pytest_collect_file(file_path, path, parent):
|
||||||
|
+def pytest_collect_file(file_path, parent):
|
||||||
|
config = parent.config
|
||||||
|
- if config.option.black and path.ext in [".py", ".pyi"]:
|
||||||
|
+ if config.option.black and file_path.suffix in [".py", ".pyi"]:
|
||||||
|
return BlackFile.from_parent(parent, path=file_path)
|
||||||
|
|
||||||
|
|
||||||
BIN
pytest_black-0.6.0.tar.gz
LFS
Normal file
BIN
pytest_black-0.6.0.tar.gz
LFS
Normal file
Binary file not shown.
@@ -1,3 +1,26 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Tue Jan 20 14:40:05 UTC 2026 - Daniel Garcia <daniel.garcia@suse.com>
|
||||||
|
|
||||||
|
- Add patch pytest9.patch make it work with pytest 9.0
|
||||||
|
https://docs.pytest.org/en/latest/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
Tue Nov 25 00:42:23 UTC 2025 - Steve Kowalik <steven.kowalik@suse.com>
|
||||||
|
|
||||||
|
- Update to 0.6.0:
|
||||||
|
* Check both py and pyi files.
|
||||||
|
* Adopt to pytest 7.
|
||||||
|
* Remove no longer compatible tests.
|
||||||
|
* Move project metadata to new home.
|
||||||
|
- Update URL.
|
||||||
|
- Refresh fix-pytest-makefile.patch to match what was merged upstream.
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
Wed May 7 06:47:48 UTC 2025 - Steve Kowalik <steven.kowalik@suse.com>
|
||||||
|
|
||||||
|
- Switch to pyproject macros.
|
||||||
|
- No more greedy globs in %files.
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Mon Mar 15 10:47:48 UTC 2021 - Ben Greiner <code@bnavigator.de>
|
Mon Mar 15 10:47:48 UTC 2021 - Ben Greiner <code@bnavigator.de>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# spec file for package python-pytest-black
|
# spec file for package python-pytest-black
|
||||||
#
|
#
|
||||||
# Copyright (c) 2021 SUSE LLC
|
# Copyright (c) 2025 SUSE LLC
|
||||||
#
|
#
|
||||||
# All modifications and additions to the file contributed by third parties
|
# All modifications and additions to the file contributed by third parties
|
||||||
# remain the property of their copyright owners, unless otherwise agreed
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
@@ -16,28 +16,31 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
|
|
||||||
%define skip_python2 1
|
|
||||||
Name: python-pytest-black
|
Name: python-pytest-black
|
||||||
Version: 0.3.12
|
Version: 0.6.0
|
||||||
Release: 0
|
Release: 0
|
||||||
Summary: Black format checking plugin for pytest
|
Summary: Black format checking plugin for pytest
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: https://github.com/shopkeep/pytest-black
|
URL: https://github.com/coherent-oss/pytest-black
|
||||||
Source: https://files.pythonhosted.org/packages/source/p/pytest-black/pytest-black-%{version}.tar.gz
|
Source: https://files.pythonhosted.org/packages/source/p/pytest-black/pytest_black-%{version}.tar.gz
|
||||||
# PATCH-FIX-UPSTREAM fix-pytest-makefile.patch -- gh#shopkeep/pytest-black#53
|
# PATCH-FIX-UPSTREAM Update pytest fixtures
|
||||||
Patch0: https://github.com/shopkeep/pytest-black/pull/53.patch#/fix-pytest-makefile.patch
|
Patch0: https://github.com/coherent-oss/pytest-black/commit/75e0012.patch#/fix-pytest-makefile.patch
|
||||||
|
# PATCH-FIX-OPENSUSE pytest9.patch make it work with pytest 9.0
|
||||||
|
# https://docs.pytest.org/en/latest/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path
|
||||||
|
Patch1: pytest9.patch
|
||||||
|
BuildRequires: %{python_module pip}
|
||||||
BuildRequires: %{python_module setuptools_scm}
|
BuildRequires: %{python_module setuptools_scm}
|
||||||
BuildRequires: %{python_module setuptools}
|
BuildRequires: %{python_module setuptools}
|
||||||
|
BuildRequires: %{python_module wheel}
|
||||||
BuildRequires: fdupes
|
BuildRequires: fdupes
|
||||||
BuildRequires: python-rpm-macros
|
BuildRequires: python-rpm-macros
|
||||||
Requires: python-black
|
Requires: python-black
|
||||||
Requires: python-pytest >= 3.5.0
|
Requires: python-pytest >= 7
|
||||||
Requires: python-toml
|
Requires: python-toml
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
# SECTION test requirements
|
# SECTION test requirements
|
||||||
BuildRequires: %{python_module black}
|
BuildRequires: %{python_module black}
|
||||||
BuildRequires: %{python_module pytest >= 3.5.0}
|
BuildRequires: %{python_module pytest >= 7}
|
||||||
BuildRequires: %{python_module toml}
|
BuildRequires: %{python_module toml}
|
||||||
# /SECTION
|
# /SECTION
|
||||||
%python_subpackages
|
%python_subpackages
|
||||||
@@ -46,13 +49,13 @@ BuildRequires: %{python_module toml}
|
|||||||
A pytest plugin to enable format checking with black.
|
A pytest plugin to enable format checking with black.
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup -p1 -n pytest-black-%{version}
|
%autosetup -p1 -n pytest_black-%{version}
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%python_build
|
%pyproject_wheel
|
||||||
|
|
||||||
%install
|
%install
|
||||||
%python_install
|
%pyproject_install
|
||||||
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
||||||
|
|
||||||
%check
|
%check
|
||||||
@@ -61,6 +64,8 @@ A pytest plugin to enable format checking with black.
|
|||||||
%files %{python_files}
|
%files %{python_files}
|
||||||
%doc README.md
|
%doc README.md
|
||||||
%license LICENSE
|
%license LICENSE
|
||||||
%{python_sitelib}/*
|
%{python_sitelib}/pytest_black.py
|
||||||
|
%pycache_only %{python_sitelib}/__pycache__/pytest_black*.pyc
|
||||||
|
%{python_sitelib}/pytest_black-%{version}.dist-info
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
|||||||
Reference in New Issue
Block a user