【问题标题】:How run a specific GraphQLTestCase test in graphene-django?如何在 graphene-django 中运行特定的 GraphQLTestCase 测试?
【发布时间】:2021-09-14 02:17:22
【问题描述】:

导入 json

从 graphene_django.utils.testing 导入 GraphQLTestCase

从 swapi.schema 导入架构

类 FirstTestCase(GraphQLTestCase): 固定装置 = ['app/fixtures/unittest.json'] GRAPHQL_SCHEMA = 架构

def test_people_query(self):
    response = self.query(
        '''
            query{
              allPlanets {
                edges{
                  node{
                    id
                    name
                  }
                }
              }
            }
        ''',
    )
    
    self.assertResponseNoErrors(response)

    content = json.loads(response.content)
    self.assertEqual(len(content['data']['allPlanets']['edges']), 61)

def test_two(self):
    # Some test logic
    pass

我有上面的代码,我只需要运行test_two。我已经知道这个命令 python manage.py test 运行所有测试。请帮忙提前谢谢

【问题讨论】:

    标签: graphql graphene-python graphene-django


    【解决方案1】:

    您可以使用如下语法运行单独的测试方法:

    python manage.py test my_app.tests.FirstTestCase.test_two
    

    (其中my_app.tests 是包含FirstTestCase 的文件的Python 虚线路径。)Django documentation for Running tests 中的更多信息。

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 2021-01-21
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 2015-06-28
      • 2021-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多