Skip to content

Commit

Permalink
Merge pull request #118 from dougthor42/dont-have-tests-create-intern…
Browse files Browse the repository at this point in the history
…al-db-file

Dont have tests create internal db file
  • Loading branch information
dougthor42 committed Mar 1, 2019
2 parents 0cd88a5 + 64a0ea3 commit a6dde95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
import logging
from pathlib import Path
from unittest.mock import MagicMock
from unittest.mock import patch

import pytest
from _pytest.logging import caplog as _caplog
Expand Down Expand Up @@ -38,9 +40,13 @@ def app(tmp_path):
Needed to do things like creating a test client.
"""
db_file = Path(tmp_path) / "test.db"
db_file = Path(str(tmp_path)) / "test.db"

app = create_app()
# Mock out create_db - we'll do it later. If we let it happen now, then
# a database will be made using the `app.config['DATABASE']` value,
# which we don't want. (since that'll typically be `./internal.db`)
with patch('trendlines.orm.create_db', MagicMock()):
app = create_app()

# Since the `create_db` function modifies orm.db directly, we can simply
# call it here. I guess *technically* what's happening is whatever
Expand Down
15 changes: 15 additions & 0 deletions tests/test_app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
from trendlines import app_factory


@pytest.fixture(autouse=True)
def mock_create_db():
"""
Mock out ``orm.create_db`` used by ``app_factory.create_app()``.
We don't want the database file created.
This fixture is autoused for all tests in this module. Other modules
rely on the the ``conftest.app`` fixture, which also performs this
patching.
"""
with patch('trendlines.orm.create_db', MagicMock()):
yield


def test_create_app(tmp_path, monkeypatch, caplog):
# We need to touch the file or else we'll hit the FileNotFoundError
path = tmp_path / "foo.cfg"
Expand Down

0 comments on commit a6dde95

Please sign in to comment.