Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove asynctest, green and nose2 #977

Merged
merged 5 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- master
jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
Expand All @@ -23,9 +23,8 @@ jobs:
TORTOISE_MYSQL_PASS: root
TORTOISE_POSTGRES_PASS: 123456
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: [ "3.8", "3.9", "3.10" ]
steps:
- name: Start MySQL
run: sudo systemctl start mysql.service
Expand All @@ -47,15 +46,6 @@ jobs:
run: make deps
- name: Run ci
run: make ci
- name: Run green
env:
TEST_RUNNER: green
run: green
- name: Run nose2
env:
TEST_RUNNER: nose2
run: |
nose2 --plugin tortoise.contrib.test.nose2 --db-module tests.testmodels --db-url sqlite://:memory:
- name: Upload Coverage
run: coveralls --service=github
env:
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ Changed
^^^^^^^
- Move `Function`, `Aggregate` from `functions.py` to `expressions.py`. (#943)
- Move `Q` from `query_utils.py` to `expressions.py`.

Removed
^^^^^^^
- Remove `asynctest` and use `unittest.IsolatedAsyncioTestCase`. (#416)
- Remove `py37` support in tests.
- Remove `green` and `nose2` test runner.
0.17
====
0.17.8
Expand Down
401 changes: 153 additions & 248 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ pygments = "*"
bandit = "*"
black = "*"
# Test tools
tox = "*"
asynctest = "*"
green = "*"
coveralls = "*"
pytest = "*"
nose2 = "*"
pytest-xdist = "*"
pytest-cov = "*"
# Pypi
Expand Down
7 changes: 4 additions & 3 deletions tests/backends/test_connection_params.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from unittest.mock import AsyncMock, patch

import asyncpg
from asynctest.mock import CoroutineMock, patch

from tortoise import Tortoise
from tortoise.contrib import test


class TestConnectionParams(test.TestCase):
async def test_mysql_connection_params(self):
with patch("asyncmy.create_pool", new=CoroutineMock()) as mysql_connect:
with patch("asyncmy.create_pool", new=AsyncMock()) as mysql_connect:
await Tortoise._init_connections(
{
"models": {
Expand Down Expand Up @@ -42,7 +43,7 @@ async def test_mysql_connection_params(self):

async def test_postres_connection_params(self):
try:
with patch("asyncpg.create_pool", new=CoroutineMock()) as asyncpg_connect:
with patch("asyncpg.create_pool", new=AsyncMock()) as asyncpg_connect:
await Tortoise._init_connections(
{
"models": {
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def setUp(self):
if self.db_config["connections"]["models"]["engine"] != "tortoise.backends.mysql":
raise test.SkipTest("MySQL only")

async def tearDown(self) -> None:
async def asyncTearDown(self) -> None:
if Tortoise._inited:
await Tortoise._drop_databases()

Expand Down
2 changes: 1 addition & 1 deletion tests/backends/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def setUp(self):
if self.db_config["connections"]["models"]["engine"] != "tortoise.backends.asyncpg":
raise test.SkipTest("PostgreSQL only")

async def tearDown(self) -> None:
async def asyncTearDown(self) -> None:
if Tortoise._inited:
await Tortoise._drop_databases()

Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/test_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class TestPydantic(test.TestCase):
async def setUp(self) -> None:
async def asyncSetUp(self) -> None:
self.Event_Pydantic = pydantic_model_creator(Event)
self.Event_Pydantic_List = pydantic_queryset_creator(Event)
self.Tournament_Pydantic = pydantic_model_creator(Tournament)
Expand Down Expand Up @@ -1035,7 +1035,7 @@ async def test_json_field(self):


class TestPydanticCycle(test.TestCase):
async def setUp(self) -> None:
async def asyncSetUp(self) -> None:
self.Employee_Pydantic = pydantic_model_creator(Employee)

self.root = await Employee.create(name="Root")
Expand Down
5 changes: 2 additions & 3 deletions tests/model_setup/test__models__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"""

import re

from asynctest.mock import CoroutineMock, patch
from unittest.mock import AsyncMock, patch

from tortoise import Tortoise
from tortoise.contrib import test
Expand Down Expand Up @@ -35,7 +34,7 @@ async def init_for(self, module: str, safe=False) -> None:
if self.engine != "tortoise.backends.sqlite":
raise test.SkipTest("sqlite only")
with patch(
"tortoise.backends.sqlite.client.SqliteClient.create_connection", new=CoroutineMock()
"tortoise.backends.sqlite.client.SqliteClient.create_connection", new=AsyncMock()
):
await Tortoise.init(
{
Expand Down
9 changes: 4 additions & 5 deletions tests/schema/test_generate_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# pylint: disable=C0301
import re

from asynctest.mock import CoroutineMock, patch
from unittest.mock import AsyncMock, patch

from tortoise import Tortoise
from tortoise.contrib import test
Expand Down Expand Up @@ -30,7 +29,7 @@ async def tearDown(self):

async def init_for(self, module: str, safe=False) -> None:
with patch(
"tortoise.backends.sqlite.client.SqliteClient.create_connection", new=CoroutineMock()
"tortoise.backends.sqlite.client.SqliteClient.create_connection", new=AsyncMock()
):
await Tortoise.init(
{
Expand Down Expand Up @@ -396,7 +395,7 @@ async def test_m2m_no_auto_create(self):
class TestGenerateSchemaMySQL(TestGenerateSchema):
async def init_for(self, module: str, safe=False) -> None:
try:
with patch("asyncmy.create_pool", new=CoroutineMock()):
with patch("asyncmy.create_pool", new=AsyncMock()):
await Tortoise.init(
{
"connections": {
Expand Down Expand Up @@ -776,7 +775,7 @@ async def test_m2m_no_auto_create(self):
class TestGenerateSchemaPostgresSQL(TestGenerateSchema):
async def init_for(self, module: str, safe=False) -> None:
try:
with patch("asyncpg.create_pool", new=CoroutineMock()):
with patch("asyncpg.create_pool", new=AsyncMock()):
await Tortoise.init(
{
"connections": {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class TestDefault(test.TestCase):
async def setUp(self) -> None:
async def asyncSetUp(self) -> None:
connection = self.__db__
if isinstance(connection, MySQLClient):
await connection.execute_query(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class TestGroupBy(test.TestCase):
async def setUp(self) -> None:
async def asyncSetUp(self) -> None:
self.a1 = await Author.create(name="author1")
self.a2 = await Author.create(name="author2")
for i in range(10):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class TestOnlyStraight(test.TestCase):
async def setUp(self) -> None:
async def asyncSetUp(self) -> None:
self.model = StraightFields
self.instance = await self.model.create(chars="Test")

Expand Down Expand Up @@ -59,6 +59,6 @@ async def test_partial_save_with_pk(self):


class TestOnlySource(TestOnlyStraight):
async def setUp(self) -> None:
async def asyncSetUp(self) -> None:
self.model = SourceFields # type: ignore
self.instance = await self.model.create(chars="Test")
2 changes: 1 addition & 1 deletion tests/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class TestDoubleFK(test.TestCase):
r'[`"]doublefk__right[`"].[`"]id[`"]=[`"]doublefk[`"].[`"]right_id[`"]'
)

async def setUp(self) -> None:
async def asyncSetUp(self) -> None:
one = await DoubleFK.create(name="one")
two = await DoubleFK.create(name="two")
self.middle = await DoubleFK.create(name="middle", left=one, right=two)
Expand Down
39 changes: 5 additions & 34 deletions tortoise/contrib/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
from unittest import SkipTest, expectedFailure, skip, skipIf, skipUnless
from unittest.result import TestResult

from asynctest import TestCase as _TestCase
from asynctest import _fail_on
from asynctest.case import _Policy

from tortoise import Model, Tortoise
from tortoise.backends.base.config_generator import generate_config as _generate_config
from tortoise.exceptions import DBConnectionError
Expand Down Expand Up @@ -155,7 +151,7 @@ def env_initializer() -> None: # pragma: nocoverage
initializer(modules, db_url=db_url, app_label=app_label)


class SimpleTestCase(_TestCase): # type: ignore
class SimpleTestCase(unittest.IsolatedAsyncioTestCase):
"""
The Tortoise base test class.

Expand All @@ -175,15 +171,8 @@ class SimpleTestCase(_TestCase): # type: ignore
def _init_loop(self) -> None:
if self.use_default_loop:
self.loop = _LOOP
loop = None
else: # pragma: nocoverage
loop = self.loop = asyncio.new_event_loop()

policy = _Policy(asyncio.get_event_loop_policy(), loop, self.forbid_get_event_loop)

asyncio.set_event_loop_policy(policy)

self.loop = self._patch_loop(self.loop)
self.loop = asyncio.new_event_loop()

async def _setUpDB(self) -> None:
pass
Expand All @@ -193,15 +182,9 @@ async def _tearDownDB(self) -> None:

async def _setUp(self) -> None:

# initialize post-test checks
test = getattr(self, self._testMethodName)
checker = getattr(test, _fail_on._FAIL_ON_ATTR, None)
self._checker = checker or _fail_on._fail_on()
self._checker.before_test(self)

await self._setUpDB()
if asyncio.iscoroutinefunction(self.setUp):
await self.setUp()
await self.asyncSetUp()
else:
self.setUp()

Expand All @@ -210,17 +193,14 @@ async def _setUp(self) -> None:

async def _tearDown(self) -> None:
if asyncio.iscoroutinefunction(self.tearDown):
await self.tearDown()
await self.asyncTearDown()
else:
self.tearDown()
await self._tearDownDB()
Tortoise.apps = {}
Tortoise._connections = {}
Tortoise._inited = False

# post-test checks
self._checker.check_test(self)

# Override unittest.TestCase methods which call setUp() and tearDown()
def run(self, result: Optional[TestResult] = None) -> Optional[TestResult]:
orig_result = result
Expand Down Expand Up @@ -254,19 +234,10 @@ def run(self, result: Optional[TestResult] = None) -> Optional[TestResult]:

self.loop.run_until_complete(self._run_outcome(outcome, expecting_failure, testMethod))

self.loop.run_until_complete(self.doCleanups())
self._unset_loop()
for test, reason in outcome.skipped:
self._addSkip(result, test, reason)
self._feedErrorsToResult(result, outcome.errors)
if outcome.success:
if expecting_failure:
if outcome.expectedFailure:
self._addExpectedFailure(result, outcome.expectedFailure)
else: # pragma: nocoverage
self._addUnexpectedSuccess(result)
else:
result.addSuccess(self)
result.addSuccess(self)
return result
finally:
result.stopTest(self)
Expand Down