from flask import url_for

from tests.base import SampleFrontendTestBase


class BpFeaturesTestCase(SampleFrontendTestBase):
    def test_bustimes_reachable(self):
        self.assert200(self.client.get(url_for('features.bustimes')))
        self.assertTemplateUsed("bustimes.html")

from unittest.mock import patch, MagicMock

from flask import url_for

from tests.base import SampleFrontendTestBase


class BpFeaturesTestCase(SampleFrontendTestBase):
    def test_bustimes_reachable(self):
        mock = MagicMock()
        with patch('sipa.blueprints.features.get_bustimes', mock):
            resp = self.client.get(url_for('features.bustimes'))

        self.assert200(resp)
        self.assertTemplateUsed("bustimes.html")
        self.assertTrue(mock.called)

Improve test_bustimes speed by using mock
Improve test_bustimes speed by using mock

+ from unittest.mock import patch, MagicMock
+ 
  from flask import url_for
  
  from tests.base import SampleFrontendTestBase
  
  
  class BpFeaturesTestCase(SampleFrontendTestBase):
      def test_bustimes_reachable(self):
+         mock = MagicMock()
+         with patch('sipa.blueprints.features.get_bustimes', mock):
-         self.assert200(self.client.get(url_for('features.bustimes')))
+             resp = self.client.get(url_for('features.bustimes'))
+ 
+         self.assert200(resp)
          self.assertTemplateUsed("bustimes.html")
+         self.assertTrue(mock.called)
  
Improve test_bustimes speed by using mock
## Code Before:
from flask import url_for

from tests.base import SampleFrontendTestBase


class BpFeaturesTestCase(SampleFrontendTestBase):
    def test_bustimes_reachable(self):
        self.assert200(self.client.get(url_for('features.bustimes')))
        self.assertTemplateUsed("bustimes.html")

## Instruction:
Improve test_bustimes speed by using mock
## Code After:
from unittest.mock import patch, MagicMock

from flask import url_for

from tests.base import SampleFrontendTestBase


class BpFeaturesTestCase(SampleFrontendTestBase):
    def test_bustimes_reachable(self):
        mock = MagicMock()
        with patch('sipa.blueprints.features.get_bustimes', mock):
            resp = self.client.get(url_for('features.bustimes'))

        self.assert200(resp)
        self.assertTemplateUsed("bustimes.html")
        self.assertTrue(mock.called)
