Skip to content

Commit

Permalink
Merge branch 'whitespace/dev' of github.com:HSamiul/cakepop-pytest in…
Browse files Browse the repository at this point in the history
…to whitespace/dev
  • Loading branch information
mthaitan committed May 6, 2023
2 parents 7e05578 + a8a8e49 commit f083d5c
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 71 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
exclude: _pytest/(debugging|hookspec).py
language_version: python3
- repo: https://github.com/PyCQA/autoflake
rev: v2.1.0
rev: v2.1.1
hooks:
- id: autoflake
name: autoflake
Expand All @@ -44,7 +44,7 @@ repos:
- id: reorder-python-imports
args: ['--application-directories=.:src', --py37-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.3.2
hooks:
- id: pyupgrade
args: [--py37-plus]
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Benjamin Peterson
Bernard Pratz
Bob Ippolito
Brian Dorsey
Brian Larsen
Brian Maissy
Brian Okken
Brianna Laugher
Expand Down
3 changes: 3 additions & 0 deletions changelog/10940.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Improved verbose output (``-vv``) of ``skip`` and ``xfail`` reasons by performing text wrapping while leaving a clear margin for progress output.

Added :func:`TerminalReporter.wrap_write() <pytest.TerminalReporter.wrap_write>` as a helper for that.
17 changes: 17 additions & 0 deletions doc/en/explanation/goodpractices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,20 @@ See also `pypa/setuptools#1684 <https://github.com/pypa/setuptools/issues/1684>`

setuptools intends to
`remove the test command <https://github.com/pypa/setuptools/issues/931>`_.

Checking with flake8-pytest-style
---------------------------------

In order to ensure that pytest is being used correctly in your project,
it can be helpful to use the `flake8-pytest-style <https://github.com/m-burst/flake8-pytest-style>`_ flake8 plugin.

flake8-pytest-style checks for common mistakes and coding style violations in pytest code,
such as incorrect use of fixtures, test function names, and markers.
By using this plugin, you can catch these errors early in the development process
and ensure that your pytest code is consistent and easy to maintain.

A list of the lints detected by flake8-pytest-style can be found on its `PyPI page <https://pypi.org/project/flake8-pytest-style/>`_.

.. note::

flake8-pytest-style is not an official pytest project. Some of the rules enforce certain style choices, such as using `@pytest.fixture()` over `@pytest.fixture`, but you can configure the plugin to fit your preferred style.
7 changes: 3 additions & 4 deletions doc/en/index.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
:orphan:

..
.. sidebar:: Next Open Trainings
.. sidebar:: Next Open Trainings

- `Professional Testing with Python <https://python-academy.com/courses/python_course_testing.html>`_, via `Python Academy <https://www.python-academy.com/>`_, March 7th to 9th 2023 (3 day in-depth training), Remote
- `Professional Testing with Python <https://python-academy.com/courses/python_course_testing.html>`_, via `Python Academy <https://www.python-academy.com/>`_, March 5th to 7th 2024 (3 day in-depth training), Leipzig/Remote

Also see :doc:`previous talks and blogposts <talks>`.
Also see :doc:`previous talks and blogposts <talks>`.

.. _features:

Expand Down
162 changes: 113 additions & 49 deletions doc/en/reference/plugin_list.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ All the command-line flags can be obtained by running ``pytest --help``::
Auto-indent multiline messages passed to the logging
module. Accepts true|on, false|off or an integer.
--log-disable=LOGGER_DISABLE
Disable a logger by name. Can be passed multipe
Disable a logger by name. Can be passed multiple
times.

[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg|pyproject.toml file found:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/_py/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ def ensure(self, *args, **kwargs):
else:
p.dirpath()._ensuredirs()
if not p.check(file=1):
p.open("w").close()
p.open("wb").close()
return p

@overload
Expand Down
4 changes: 3 additions & 1 deletion src/_pytest/faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def pytest_configure(config: Config) -> None:
import faulthandler

stderr_fd_copy = os.dup(get_stderr_fileno())
config.stash[fault_handler_stderr_key] = open(stderr_fd_copy, "w")
config.stash[fault_handler_stderr_key] = open(
stderr_fd_copy, "w", encoding=sys.stderr.encoding
)
config.stash[fault_handler_originally_enabled_key] = faulthandler.is_enabled()
faulthandler.enable(file=config.stash[fault_handler_stderr_key])

Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def add_option_ini(option, dest, default=None, type=None, **kwargs):
action="append",
default=[],
dest="logger_disable",
help="Disable a logger by name. Can be passed multipe times.",
help="Disable a logger by name. Can be passed multiple times.",
)


Expand Down
25 changes: 24 additions & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import inspect
import platform
import sys
import textwrap
import warnings
from collections import Counter
from functools import partial
Expand Down Expand Up @@ -426,6 +427,28 @@ def ensure_newline(self) -> None:
self._tw.line()
self.currentfspath = None

def wrap_write(
self,
content: str,
*,
flush: bool = False,
margin: int = 8,
line_sep: str = "\n",
**markup: bool,
) -> None:
"""Wrap message with margin for progress info."""
width_of_current_line = self._tw.width_of_current_line
wrapped = line_sep.join(
textwrap.wrap(
" " * width_of_current_line + content,
width=self._screen_width - margin,
drop_whitespace=True,
replace_whitespace=False,
),
)
wrapped = wrapped[width_of_current_line:]
self._tw.write(wrapped, flush=flush, **markup)

def write(self, content: str, *, flush: bool = False, **markup: bool) -> None:
self._tw.write(content, flush=flush, **markup)

Expand Down Expand Up @@ -572,7 +595,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
formatted_reason = f" ({reason})"

if reason and formatted_reason is not None:
self._tw.write(formatted_reason)
self.wrap_write(formatted_reason)
if self._show_progress_info:
self._write_progress_information_filling_space()
else:
Expand Down
8 changes: 6 additions & 2 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,15 @@ def test_cmdline_python_namespace_package(
monkeypatch.chdir("world")

# pgk_resources.declare_namespace has been deprecated in favor of implicit namespace packages.
# pgk_resources has been deprecated entirely.
# While we could change the test to use implicit namespace packages, seems better
# to still ensure the old declaration via declare_namespace still works.
ignore_w = r"-Wignore:Deprecated call to `pkg_resources.declare_namespace"
ignore_w = (
r"-Wignore:Deprecated call to `pkg_resources.declare_namespace",
r"-Wignore:pkg_resources is deprecated",
)
result = pytester.runpytest(
"--pyargs", "-v", "ns_pkg.hello", "ns_pkg/world", ignore_w
"--pyargs", "-v", "ns_pkg.hello", "ns_pkg/world", *ignore_w
)
assert result.ret == 0
result.stdout.fnmatch_lines(
Expand Down
4 changes: 1 addition & 3 deletions testing/test_monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,7 @@ class A:
assert A.x == 1


@pytest.mark.filterwarnings(
"ignore:Deprecated call to `pkg_resources.declare_namespace"
)
@pytest.mark.filterwarnings(r"ignore:.*\bpkg_resources\b:DeprecationWarning")
def test_syspath_prepend_with_namespace_packages(
pytester: Pytester, monkeypatch: MonkeyPatch
) -> None:
Expand Down
14 changes: 8 additions & 6 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,13 @@ def test_10():
pytest.xfail("It's 🕙 o'clock")
@pytest.mark.skip(
reason="cannot do foobar because baz is missing due to I don't know what"
reason="1 cannot do foobar because baz is missing due to I don't know what"
)
def test_long_skip():
pass
@pytest.mark.xfail(
reason="cannot do foobar because baz is missing due to I don't know what"
reason="2 cannot do foobar because baz is missing due to I don't know what"
)
def test_long_xfail():
print(1 / 0)
Expand All @@ -417,8 +417,8 @@ def test_long_xfail():
result.stdout.fnmatch_lines(
common_output
+ [
"test_verbose_skip_reason.py::test_long_skip SKIPPED (cannot *...) *",
"test_verbose_skip_reason.py::test_long_xfail XFAIL (cannot *...) *",
"test_verbose_skip_reason.py::test_long_skip SKIPPED (1 cannot *...) *",
"test_verbose_skip_reason.py::test_long_xfail XFAIL (2 cannot *...) *",
]
)

Expand All @@ -428,12 +428,14 @@ def test_long_xfail():
+ [
(
"test_verbose_skip_reason.py::test_long_skip SKIPPED"
" (cannot do foobar because baz is missing due to I don't know what) *"
" (1 cannot do foobar"
),
"because baz is missing due to I don't know what) *",
(
"test_verbose_skip_reason.py::test_long_xfail XFAIL"
" (cannot do foobar because baz is missing due to I don't know what) *"
" (2 cannot do foobar"
),
"because baz is missing due to I don't know what) *",
]
)

Expand Down

0 comments on commit f083d5c

Please sign in to comment.