Skip to content

Commit e9deab9

Browse files
committed
fix pytest fixture warnings
1 parent 4c59ad8 commit e9deab9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

tests/models.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
@pytest.fixture
2525
def random_name(length=8) -> str:
26+
return _random_name(length)
27+
28+
29+
def _random_name(length=8):
2630
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
2731

2832

@@ -34,7 +38,7 @@ class User(db.Model):
3438
__tablename__ = 'gino_users'
3539

3640
id = db.Column(db.BigInteger(), primary_key=True)
37-
nickname = db.Column('name', db.Unicode(), default='noname')
41+
nickname = db.Column('name', db.Unicode(), default=_random_name)
3842
profile = db.Column('props', JSONB(), nullable=False, server_default='{}')
3943
type = db.Column(
4044
db.Enum(UserType),
@@ -78,7 +82,7 @@ class Team(db.Model):
7882
__tablename__ = 'gino_teams'
7983

8084
id = db.Column(db.BigInteger(), primary_key=True)
81-
name = db.Column(db.Unicode(), default=random_name)
85+
name = db.Column(db.Unicode(), default=_random_name)
8286
parent_id = db.Column(db.ForeignKey('gino_teams.id'))
8387
company_id = db.Column(db.ForeignKey('gino_companies.id'))
8488

@@ -99,7 +103,7 @@ class Company(db.Model):
99103
__tablename__ = 'gino_companies'
100104

101105
id = db.Column(db.BigInteger(), primary_key=True)
102-
name = db.Column(db.Unicode(), default=random_name)
106+
name = db.Column(db.Unicode(), default=_random_name)
103107
logo = db.Column(db.LargeBinary())
104108

105109
def __init__(self, **kw):

tests/test_quart.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from .models import DB_ARGS, PG_URL
1818

19+
pytestmark = pytest.mark.asyncio
20+
1921

2022
# noinspection PyShadowingNames
2123
async def _app(config):
@@ -120,12 +122,10 @@ async def _test_index_returns_200(app):
120122
assert await response.get_data(raw=False) == 'Hello, world!'
121123

122124

123-
@pytest.mark.asyncio
124125
async def test_index_returns_200(app):
125126
await _test_index_returns_200(app)
126127

127128

128-
@pytest.mark.asyncio
129129
async def test_index_returns_200_dsn(app_dsn):
130130
await _test_index_returns_200(app_dsn)
131131

@@ -148,12 +148,10 @@ async def _test(app):
148148
assert await response.get_json() == dict(id=1, nickname='fantix')
149149

150150

151-
@pytest.mark.asyncio
152151
async def test(app):
153152
await _test(app)
154153

155154

156-
@pytest.mark.asyncio
157155
async def test_dsn(app_dsn):
158156
await _test(app_dsn)
159157

@@ -181,11 +179,9 @@ async def _test_websocket(app):
181179
assert response == dict(id=1, nickname='fantix')
182180

183181

184-
@pytest.mark.asyncio
185182
async def test_ws(app):
186183
await _test_websocket(app)
187184

188185

189-
@pytest.mark.asyncio
190186
async def test_ws_dsn(app_dsn):
191187
await _test_websocket(app_dsn)

0 commit comments

Comments
 (0)