From 5ce7b7fcde37e305e44d133e2f2026eef6e77bf5 Mon Sep 17 00:00:00 2001 From: Balint Csergo Date: Fri, 30 Sep 2022 08:48:46 -0700 Subject: [PATCH] remove python 3.6 support (#340) Summary: Remove python 3.6 support and related ifs Pull Request resolved: https://github.com/facebook/TestSlide/pull/340 Reviewed By: pedroforjazfigueiredo Differential Revision: D39852113 Pulled By: deathowl fbshipit-source-id: 34149c5c2a779a28ea30fec38e8ad48eecbaf0cf --- .github/workflows/build.yml | 2 +- .../tests/test_pytest_testslide.py | 7 +-- tests/dsl_unittest.py | 49 +++++++------------ tests/testcase_unittest.py | 9 +--- testslide/__init__.py | 20 +------- testslide/lib.py | 2 +- 6 files changed, 24 insertions(+), 65 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85f12a35..91bc5396 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + python-version: ["3.7", "3.8", "3.9", "3.10"] # Ensure that all flavours are run to completion even if an other flavor failed fail-fast: false diff --git a/pytest-testslide/tests/test_pytest_testslide.py b/pytest-testslide/tests/test_pytest_testslide.py index 120f9e88..9d7f0bd5 100644 --- a/pytest-testslide/tests/test_pytest_testslide.py +++ b/pytest-testslide/tests/test_pytest_testslide.py @@ -3,7 +3,6 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import re -import sys def test_pass(testdir): @@ -126,11 +125,7 @@ def test_aggregated_exceptions(testslide): sample_module.CallOrderTarget("c").f1("a") """ ) - # asyncio-mode is not supported on python3.6 - if sys.version_info >= (3, 7): - result = testdir.runpytest("-v", "--asyncio-mode=auto") - else: - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", "--asyncio-mode=auto") assert "passed, 4 errors" in result.stdout.str() assert "failed" not in result.stdout.str() expected_failure = re.compile( diff --git a/tests/dsl_unittest.py b/tests/dsl_unittest.py index a2b46abb..412e5c99 100644 --- a/tests/dsl_unittest.py +++ b/tests/dsl_unittest.py @@ -6,7 +6,6 @@ import asyncio import os import subprocess -import sys import time import unittest from typing import List @@ -1909,29 +1908,25 @@ async def example(self): ): self.run_first_context_first_example() - if sys.version_info >= (3, 7): - - def test_fail_if_coroutine_not_awaited(self): - @context - def top(context): - @context.example - async def example(self): - asyncio.sleep(0.1) + def test_fail_if_coroutine_not_awaited(self): + @context + def top(context): + @context.example + async def example(self): + asyncio.sleep(0.1) - with self.assertRaisesRegex( - RuntimeWarning, "coroutine '.+' was never awaited" - ): - self.run_first_context_first_example() + with self.assertRaisesRegex(RuntimeWarning, "coroutine '.+' was never awaited"): + self.run_first_context_first_example() - def test_fail_if_slow_task(self): - @context - def top(context): - @context.example - async def example(self): - time.sleep(0.1) + def test_fail_if_slow_task(self): + @context + def top(context): + @context.example + async def example(self): + time.sleep(0.1) - with self.assertRaisesRegex(SlowCallback, "^Executing .+ took .+ seconds"): - self.run_first_context_first_example() + with self.assertRaisesRegex(SlowCallback, "^Executing .+ took .+ seconds"): + self.run_first_context_first_example() def test_resetting_attribute_raises_ValueError(self): @context @@ -2053,11 +2048,7 @@ async def dummy_async_func(): def fail_top(context): @context.example async def spawn_task_but_dont_await(self): - if sys.version_info < (3, 7): - loop = asyncio.get_event_loop() - loop.create_task(dummy_async_func()) - else: - asyncio.create_task(dummy_async_func()) + asyncio.create_task(dummy_async_func()) examples = _get_name_to_examples() @@ -2129,11 +2120,7 @@ async def dummy_async_func(): pass async def spawn_task_but_dont_await(): - if sys.version_info < (3, 7): - loop = asyncio.get_event_loop() - loop.create_task(dummy_async_func()) - else: - asyncio.create_task(dummy_async_func()) + asyncio.create_task(dummy_async_func()) @context def fail_top(context): diff --git a/tests/testcase_unittest.py b/tests/testcase_unittest.py index cd78d6a9..21c5c202 100644 --- a/tests/testcase_unittest.py +++ b/tests/testcase_unittest.py @@ -5,7 +5,6 @@ import asyncio import csv -import sys import unittest import testslide @@ -41,13 +40,7 @@ def test_has_mock_async_callable(self): self.mock_async_callable(SomeClass, "async_do_something").to_return_value( 42 ).and_assert_called_once() - if sys.version_info >= (3, 7): - self.assertEqual(asyncio.run(SomeClass.async_do_something()), 42) - else: - loop = asyncio.get_event_loop() - result = loop.run_until_complete(SomeClass.async_do_something()) - loop.close() - self.assertEqual(result, 42) + self.assertEqual(asyncio.run(SomeClass.async_do_something()), 42) def test_has_mock_constructor(self): dict_reader = testslide.StrictMock(csv.DictReader) diff --git a/testslide/__init__.py b/testslide/__init__.py index a91abb67..502bcfff 100644 --- a/testslide/__init__.py +++ b/testslide/__init__.py @@ -45,24 +45,11 @@ # hack for Mypy from testslide.runner import BaseFormatter -if sys.version_info < (3, 6): - raise RuntimeError("Python >=3.6 required.") - if sys.version_info < (3, 7): + raise RuntimeError("Python >=3.7 required.") - def asyncio_run(coro): - loop = asyncio.events.new_event_loop() - try: - loop.set_debug(True) - loop.run_until_complete(coro) - finally: - try: - loop.run_until_complete(loop.shutdown_asyncgens()) - finally: - loop.close() -else: - asyncio_run = partial(asyncio.run, debug=True) +asyncio_run = partial(asyncio.run, debug=True) if sys.version_info < (3, 8): @@ -400,9 +387,6 @@ async def async_wrapped() -> None: @contextlib.contextmanager def _raise_if_asyncio_warnings(self, context_data: _ContextData) -> Iterator[None]: - if sys.version_info < (3, 7): - yield - return original_showwarning = warnings.showwarning caught_failures: List[Union[Exception, str]] = [] diff --git a/testslide/lib.py b/testslide/lib.py index d0a35c07..de194c14 100644 --- a/testslide/lib.py +++ b/testslide/lib.py @@ -32,7 +32,7 @@ def get_args(tp): return tp.__args__ return () -else: # python3.6 +else: from typing import GenericMeta # type: ignore def get_origin(tp):