Make tox run faster by using in-memory sqlite db. (#1752)
Two tests were invariably grinding my system to a halt as it was applying migrations to an empty sqlite database. This patch reduces the time of a pytest run from 50 to about 16 seconds on my desktop. The difference is even more noticable on a slower laptop drive, but is probably insignificant for all you fancy SSD users.
This commit is contained in:
1 parent
f5227e1de0
commit
c481cbce7e
3 files changed
+8
-11
No files matched your search
@@ -1,7 +1,6 @@
|
||||
"""The tests the History component."""
|
||||
# pylint: disable=protected-access,too-many-public-methods
|
||||
from datetime import timedelta
|
||||
import os
|
||||
import unittest
|
||||
from unittest.mock import patch, sentinel
|
||||
|
||||
@@ -24,13 +23,10 @@ class TestComponentHistory(unittest.TestCase):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
db_path = self.hass.config.path(recorder.DB_FILE)
|
||||
if os.path.isfile(db_path):
|
||||
os.remove(db_path)
|
||||
|
||||
def init_recorder(self):
|
||||
"""Initialize the recorder."""
|
||||
recorder.setup(self.hass, {})
|
||||
with patch('homeassistant.core.Config.path', return_value=':memory:'):
|
||||
recorder.setup(self.hass, {})
|
||||
self.hass.start()
|
||||
self.wait_recording_done()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""The tests for the Recorder component."""
|
||||
# pylint: disable=too-many-public-methods,protected-access
|
||||
import unittest
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.const import MATCH_ALL
|
||||
from homeassistant.components import recorder
|
||||
@@ -15,7 +15,8 @@ class TestRecorder(unittest.TestCase):
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
recorder.setup(self.hass, {})
|
||||
with patch('homeassistant.core.Config.path', return_value=':memory:'):
|
||||
recorder.setup(self.hass, {})
|
||||
self.hass.start()
|
||||
recorder._INSTANCE.block_till_done()
|
||||
|
||||
@@ -23,7 +24,6 @@ class TestRecorder(unittest.TestCase):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
recorder._INSTANCE.block_till_done()
|
||||
os.remove(self.hass.config.path(recorder.DB_FILE))
|
||||
|
||||
def test_saving_state(self):
|
||||
"""Test saving and restoring a state."""
|
||||
|
||||
Reference in new issue
Block a user