接口测试 请问下,pytest.fixture 和 pytest.mark.parametrize 两者的执行顺序问题

王加 · 2021年03月11日 · 最后由 王加 回复于 2021年03月12日 · 2013 次阅读


我在 pytest.fixture 中通过 A 接口生成了一个参数集合的文件,之后在用例中通过 pytest.mark.parametrize 调用,然后发现 pytest.mark.parametrize 中的 yaml.safe_load(open('data/all_test_data/hot_key_word.yaml', encoding='utf-8') 这一句的执行在 pytest.fixture 之前。

@pytest.fixture(scope='function')
   def generate_hot_keyword(self):
       print('generate_hot_keyword_setup')
       entrys = yaml.safe_load(open('data/all_test_data/search_entry.yaml'))
       file_path = 'data/all_test_data/hot_key_word.yaml'
       handle_yaml.remove_yaml_msg(file_path)
       for entry in entrys:
           result = self.get_search_online.get_hot_search(entry).json()
           result_list = handle_result_list.handle_hot_keyword_result(result)
           handle_yaml.generate_yaml_msg(result_list, file_path)
@user2ize('keyword',  yaml.safe_load(open('data/all_test_data/hot_key_word.yaml', encoding='utf-8')))
    def test_hot_key_search(self, keyword, generate_hot_keyword):
        type_id = '31'
        r = self.get_search_online.get_keyword_search(type_id, keyword)
        assert_tool.assert_data_type_list(r.json())

请问下,这种参数生成的是不是不能用 fixture 处理,谢谢各位
尝试过将 A 接口的处理设计成一个函数,但是这样处理了之后,我就取不到通过命令行传递过来接口域名了。求帮忙解答一下

共收到 4 条回复 时间 点赞

你写在前面肯定是在前面执行的

写在前面,前面的先执行是什么意思呀

王加 回复

我知道你意思了,麻烦问下,这个有没有什么解决办法呢

我知道你意思了,请问下,这个有没有什么解决办法呢

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册