From 21ec6863d7f8380d66c39f1ed3b8d9cc0dc86e49 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Mon, 28 Sep 2020 18:34:53 +0300 Subject: Fix failing test * wqflask/tests/base/test_trait.py: Add app_context to test class, otherwise an error related to working outside the app_context is generated. Adding the app_context is required when mocking "Flask.g". --- wqflask/tests/base/test_trait.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'wqflask/tests/base') diff --git a/wqflask/tests/base/test_trait.py b/wqflask/tests/base/test_trait.py index 60ebaee0..826ccefd 100644 --- a/wqflask/tests/base/test_trait.py +++ b/wqflask/tests/base/test_trait.py @@ -3,6 +3,7 @@ import unittest from unittest import mock +from wqflask import app from base.trait import GeneralTrait from base.trait import retrieve_trait_info @@ -31,6 +32,14 @@ class MockTrait(GeneralTrait): class TestRetrieveTraitInfo(unittest.TestCase): """Tests for 'retrieve_trait_info'""" + + def setUp(self): + self.app_context = app.app_context() + self.app_context.push() + + def tearDown(self): + self.app_context.pop() + def test_retrieve_trait_info_with_empty_dataset(self): """Test that an exception is raised when dataset is empty""" with self.assertRaises(AssertionError): @@ -104,7 +113,7 @@ class TestRetrieveTraitInfo(unittest.TestCase): resource_id_mock, g_mock, requests_mock): - """Test """ + """Test retrieve trait info when lrs has a value""" resource_id_mock.return_value = 1 g_mock.db.execute.return_value.fetchone = mock.Mock() g_mock.db.execute.return_value.fetchone.side_effect = [ -- cgit v1.2.3