How to apply integration tests (rather than unit tests) to a Flask RESTful API

后端 未结 4 1617
不知归路
不知归路 2020-12-14 01:36

[As per https://stackoverflow.com/a/46369945/1021819, the title should refer to integration tests rather than unit tests]

Suppose I\'d like to test the foll

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 02:26

    Flask provides a test_client you can use in your tests:

    from source.api import app
    from unittest import TestCase
    
    class TestIntegrations(TestCase):
        def setUp(self):
            self.app = app.test_client()
    
        def test_thing(self):
            response = self.app.get('/')
            assert 
    

    Flask Testing Docs

提交回复
热议问题