我正在 Ubuntu (20.04) 上的 VSCode (1.46.1) 中创建一个带有 CMake (3.16.3) 和 pybind11 (2.4.3) 的入门项目,默认情况下它同时具有 Python 2.7 和 3.8。我想为 Python3 构建一个模块。当我在 CMakeLists.txt 中使用以下两行时
find_package(pybind11)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
Run Code Online (Sandbox Code Playgroud)
CMake 配置是
[cmake] -- Found PythonInterp: /usr/bin/python (found version "2.7.18")
[cmake] -- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so
[cmake] -- Found Python3: /usr/bin/python3.8 (found version "3.8.2") found components: Interpreter Development
Run Code Online (Sandbox Code Playgroud)
切换 find_package 语句的顺序
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11)
Run Code Online (Sandbox Code Playgroud)
提供相同的 python 链接,但使用新的顺序
[cmake] -- Found Python: /usr/bin/python3.8 (found version "3.8.2") found components: Interpreter Development
[cmake] -- …Run Code Online (Sandbox Code Playgroud) 我想对我的 Python Azure 函数进行单元测试。我正在关注微软文档。
文档模拟了对该函数的调用,如下所示
req = func.HttpRequest(
method='GET',
body=None,
url='/api/HttpTrigger',
params={'name': 'Test'})
Run Code Online (Sandbox Code Playgroud)
我想这样做,但将参数作为 JSON 对象传递,以便我可以跟踪req_body = req.get_json()函数代码的分支。我想我可以通过像这样的函数调用来做到这一点
req = func.HttpRequest(
method='GET',
body=json.dumps({'name': 'Test'}),
url='/api/HttpTrigger',
params=None)
Run Code Online (Sandbox Code Playgroud)
如果我像这样构造调用,req.get_json()则会失败并显示错误消息AttributeError: 'str' object has no attribute 'decode'。
如何使用 JSON 输入参数构造请求?这应该是微不足道的,但我显然错过了一些明显的东西。