#7 Fix tests with Python 3.11 + Use pytest-xdist and run the tests in parallel
Merged 6 months ago by churchyard. Opened 6 months ago by churchyard.
rpms/ churchyard/pre-commit python3.11  into  rawhide

file modified
+11 -1
@@ -9,6 +9,13 @@ 

  URL:            https://pre-commit.com

  Source0:        https://github.com/%{name}/%{name}/archive/v%{version}/%{name}-%{version}.tar.gz

  

+ # https://github.com/pre-commit/pre-commit/issues/2450

+ Patch:          python3.11-dont-error-with-importlib-deprecation-warnings.patch

+ 

+ # https://github.com/pre-commit/pre-commit/issues/2451

+ # https://github.com/pre-commit/pre-commit/pull/2453

+ Patch:          python3.11-enhanced-tracebacks-in-tests.patch

+ 

  BuildArch:      noarch

  

  BuildRequires:  python3-devel
@@ -39,6 +46,9 @@ 

  BuildRequires:  perl-CPAN

  BuildRequires:  rubypick

  BuildRequires:  rubygems

+ 

+ # Manually added to speed up the %%check section

+ BuildRequires:  python3dist(pytest-xdist)

  %endif

  

  %description
@@ -115,7 +125,7 @@ 

  k="${k-}${k+ and }not test_installed_from_venv"

  # Fails in koji but not local mock (hook exits with code 1, no useful output)

  k="${k-}${k+ and }not test_run_a_ruby_hook"

- %pytest -v -k "${k-}"

+ %pytest -v -k "${k-}" -n %{_smp_build_ncpus}

  %endif

  

  

@@ -0,0 +1,21 @@ 

+ diff --git a/tests/conftest.py b/tests/conftest.py

+ index b68a1d0..b04680b 100644

+ --- a/tests/conftest.py

+ +++ b/tests/conftest.py

+ @@ -28,11 +28,14 @@ def no_warnings(recwarn):

+      for warning in recwarn:  # pragma: no cover

+          message = str(warning.message)

+          # ImportWarning: Not importing directory '...' missing __init__(.py)

+ -        if not (

+ +        if not ((

+              isinstance(warning.message, ImportWarning) and

+              message.startswith('Not importing directory ') and

+              ' missing __init__' in message

+ -        ):

+ +        ) or (

+ +            isinstance(warning.message, DeprecationWarning) and

+ +            '#migrating-from-legacy' in message

+ +        )):

+              warnings.append(

+                  f'{warning.filename}:{warning.lineno} {message}',

+              )

@@ -0,0 +1,50 @@ 

+ From 901e831313e897e3b9313f5efbb5ef589b3e279c Mon Sep 17 00:00:00 2001

+ From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>

+ Date: Sun, 10 Jul 2022 02:03:56 +0200

+ Subject: [PATCH] Tests: Adjust traceback regexes to allow Python 3.11+ ^^^^^^^

+ 

+ Fixes https://github.com/pre-commit/pre-commit/issues/2451

+ ---

+  tests/error_handler_test.py | 6 ++++++

+  1 file changed, 6 insertions(+)

+ 

+ diff --git a/tests/error_handler_test.py b/tests/error_handler_test.py

+ index 31c71d287..47e2afaa4 100644

+ --- a/tests/error_handler_test.py

+ +++ b/tests/error_handler_test.py

+ @@ -45,9 +45,11 @@ def test_error_handler_fatal_error(mocked_log_and_exit):

+          r'Traceback \(most recent call last\):\n'

+          r'  File ".+pre_commit.error_handler.py", line \d+, in error_handler\n'

+          r'    yield\n'

+ +        r'(    \^\^\^\^\^\n)?'

+          r'  File ".+tests.error_handler_test.py", line \d+, '

+          r'in test_error_handler_fatal_error\n'

+          r'    raise exc\n'

+ +        r'(    \^\^\^\^\^\^\^\^\^\n)?'

+          r'(pre_commit\.errors\.)?FatalError: just a test\n',

+      )

+      pattern.assert_matches(mocked_log_and_exit.call_args[0][3])

+ @@ -69,9 +71,11 @@ def test_error_handler_uncaught_error(mocked_log_and_exit):

+          r'Traceback \(most recent call last\):\n'

+          r'  File ".+pre_commit.error_handler.py", line \d+, in error_handler\n'

+          r'    yield\n'

+ +        r'(    \^\^\^\^\^\n)?'

+          r'  File ".+tests.error_handler_test.py", line \d+, '

+          r'in test_error_handler_uncaught_error\n'

+          r'    raise exc\n'

+ +        r'(    \^\^\^\^\^\^\^\^\^\n)?'

+          r'ValueError: another test\n',

+      )

+      pattern.assert_matches(mocked_log_and_exit.call_args[0][3])

+ @@ -93,9 +97,11 @@ def test_error_handler_keyboardinterrupt(mocked_log_and_exit):

+          r'Traceback \(most recent call last\):\n'

+          r'  File ".+pre_commit.error_handler.py", line \d+, in error_handler\n'

+          r'    yield\n'

+ +        r'(    \^\^\^\^\^\n)?'

+          r'  File ".+tests.error_handler_test.py", line \d+, '

+          r'in test_error_handler_keyboardinterrupt\n'

+          r'    raise exc\n'

+ +        r'(    \^\^\^\^\^\^\^\^\^\n)?'

+          r'KeyboardInterrupt\n',

+      )

+      pattern.assert_matches(mocked_log_and_exit.call_args[0][3])

no initial comment

Pull-Request has been merged by churchyard

6 months ago

Building pre-commit-2.19.0-2.fc37 for rawhide
Created task: 89315321
Task info: https://koji.fedoraproject.org/koji/taskinfo?taskID=89315321