Aiohttp: 参数“ loop_factory”应通过间接或在函数本身中显式声明

创建于 2020-03-12  ·  3评论  ·  资料来源: aio-libs/aiohttp

尝试从3.7.2升级到3.8.1时,我在py.test中通过测试发现开始看到以下内容:

参数“ loop_factory”应通过间接或在函数本身中显式声明

事实证明它是异步函数,它似乎是在aiohttp中的某个地方引起的。 我对asyncio或aiohttp不太熟悉,因此很乐意在指导下进行更多调试,但是我希望有人在这里有更多的想法。

相关软件包:

aiohttp==3.6.2
pytest==5.4.0
pytest-aiohttp==0.3.0
pytest-cov==2.8.1
pytest-forked==1.1.3
pytest-mock==2.0.0
pytest-responses==0.4.0
pytest-xdist==1.31.0

有关调用栈的一些细节:

➜  ~/D/zeus (feat/increase-lru-cache) ✗ py.test -x --pdb
=========================================================================================== test session starts ============================================================================================
platform darwin -- Python 3.8.1, pytest-5.4.0, py-1.8.1, pluggy-0.13.1
rootdir: /Users/dcramer/Development/zeus, inifile: setup.cfg
plugins: mock-2.0.0, celery-4.1.1, xdist-1.31.0, aiohttp-0.3.0, forked-1.1.3, responses-0.4.0, cov-2.8.1
collecting 186 items
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
In function "test_health_check":
Parameter "loop_factory" should be declared explicitly via indirect or in function itself
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /Users/dcramer/Development/zeus/.venv/lib/python3.8/site-packages/_pytest/python.py(1144)_validate_explicit_parameters()
-> fail(msg, pytrace=False)
(Pdb) l
1139                    func_name = self.function.__name__
1140                    msg = (
1141                        'In function "{func_name}":\n'
1142                        'Parameter "{arg}" should be declared explicitly via indirect or in function itself'
1143                    ).format(func_name=func_name, arg=arg)
1144 ->                 fail(msg, pytrace=False)
1145
1146
1147    def _find_parametrized_scope(argnames, arg2fixturedefs, indirect):
1148        """Find the most appropriate scope for a parametrized call based on its arguments.
1149
(Pdb) u
> /Users/dcramer/Development/zeus/.venv/lib/python3.8/site-packages/_pytest/python.py(939)parametrize()
-> self._validate_explicit_parameters(argnames, indirect)
(Pdb) l
934
935             self._validate_if_using_arg_names(argnames, indirect)
936
937             arg_values_types = self._resolve_arg_value_types(argnames, indirect)
938
939  ->         self._validate_explicit_parameters(argnames, indirect)
940
941             # Use any already (possibly) generated ids with parametrize Marks.
942             if _param_mark and _param_mark._param_ids_from:
943                 generated_ids = _param_mark._param_ids_from._param_ids_generated
944                 if generated_ids is not None:
(Pdb) u
> /Users/dcramer/Development/zeus/.venv/lib/python3.8/site-packages/aiohttp/pytest_plugin.py(203)pytest_generate_tests()
-> metafunc.parametrize("loop_factory",
(Pdb) l
198                         "Unknown loop '%s', available loops: %s" % (
199                             name, list(factories.keys())))
200                 else:
201                     continue
202             factories[name] = avail_factories[name]
203  ->     metafunc.parametrize("loop_factory",
204                              list(factories.values()),
205                              ids=list(factories.keys()))
206
207
208     @pytest.fixture

所有3条评论

正如我现在在3.7.2中看到的那样,这实际上可能与3.8.x不相关。 打算继续一分为二。

这是由于释放pytest==5.4.0 。 我只是被它烧死了,然后回滚到pytest<5.4可以解决问题。

是的,你是对的。 在我的调试中就做到了:)。

希望这对谷歌搜索有所帮助。 将在pytest上进行分类。

此页面是否有帮助?
0 / 5 - 0 等级