Skip to content

Commit

Permalink
Fix F811 rule, move fixtures to conftest.py
Browse files Browse the repository at this point in the history
Moved fixtures from test_utils module to a special conftest.py file that
is grabbed automatically by pytest. This fixes the F811 Flake8 rule
complaining about test function argument names clashing with the pytest
fixture function name.
  • Loading branch information
Glutexo committed Jul 11, 2019
1 parent c91e5e0 commit 74a7bbb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
22 changes: 22 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pytest import fixture

from app import create_app, db
from test_utils import rename_host_table_and_indexes


@fixture
def flask_app_fixture():
rename_host_table_and_indexes()

app = create_app(config_name="testing")

# binds the app to the current context
with app.app_context() as ctx:
# create all tables
db.create_all()
ctx.push()
yield app
ctx.pop

db.session.remove()
db.drop_all()
1 change: 0 additions & 1 deletion test_db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from app import db
from app.models import Host
from test_utils import flask_app_fixture

"""
These tests are for testing the db model classes outside of the api.
Expand Down
2 changes: 1 addition & 1 deletion test_host_dedup_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from app import db
from app.models import Host
from pytest import mark
from test_utils import flask_app_fixture


ACCOUNT_NUMBER = "000102"

Expand Down
20 changes: 0 additions & 20 deletions test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import contextlib
import os
import pytest
import unittest.mock

from app import create_app, db
from app.models import Host


Expand Down Expand Up @@ -33,21 +31,3 @@ def rename_host_table_and_indexes():
for index in Host.__table_args__:
if temp_table_name_suffix not in index.name:
index.name = index.name + temp_table_name_suffix


@pytest.fixture
def flask_app_fixture():
rename_host_table_and_indexes()

app = create_app(config_name="testing")

# binds the app to the current context
with app.app_context() as ctx:
# create all tables
db.create_all()
ctx.push()
yield app
ctx.pop

db.session.remove()
db.drop_all()

0 comments on commit 74a7bbb

Please sign in to comment.