简体   繁体   English

从 Python3.7 导入 pytest 而不是 2.7

[英]import pytest from Python3.7 instead 2.7

I'm new using python on kubuntu.我是在 kubuntu 上使用 python 的新手。 I'm writing some simple functions and write also tests on pytest to practise test-driven-development (although I know it's wasted on such easy functions, it's just for the sake of practice).我正在编写一些简单的函数,并在 pytest 上编写测试以练习测试驱动开发(虽然我知道它浪费在如此简单的函数上,这只是为了练习)。

Because I'm beginner, I'm writing the code in an editor and I'm executing it on the terminal, in a next step I'll use an IDE like Thonny.因为我是初学者,所以我在编辑器中编写代码并在终端上执行,下一步我将使用像 Thonny 一样的 IDE。 I have installed Python3.7, although Python2.7 seems to be the standard within the system.我已经安装了 Python3.7,虽然 Python2.7 似乎是系统内的标准。 Nonetheless, the file with the functions works fine.尽管如此,具有这些功能的文件工作正常。 I'm printing some f-strings and it works fine also.我正在打印一些 f 字符串,它也可以正常工作。 The first line of the file is a Shebang which tells the interpreter, to use Python3.7 ( #./usr/bin/env python3.7 ).该文件的第一行是一个 Shebang,它告诉解释器使用 Python3.7 ( #./usr/bin/env python3.7 )。 However, when I want to execute the tests, I'm writing pytest in console, as indicated by the pytest-introduction.但是,当我想执行测试时,我正在控制台中编写 pytest,如 pytest-introduction 所示。 Alas, I get a syntax error, because it seems that pytest is importing Python2.7 which of course doesn't know f-strings.唉,我得到一个语法错误,因为似乎 pytest 正在导入 Python2.7,它当然不知道 f 字符串。

I verified that pytest is indeed importing Python2.7 by executing the command pytest --version and I was confirmed.我通过执行命令pytest --version验证了 pytest 确实在导入 Python2.7,我得到了确认。

My question is: How can I make pytest to import Python3.7 so the test would pass or at least the Syntaxerror would go away?我的问题是:我怎样才能让 pytest 导入 Python3.7 以便测试通过或至少语法错误将 go 消失? Replacing the f-string with a normal string makes the test pass, so I'm assuming this is the only problem.用普通字符串替换 f 字符串会使测试通过,所以我假设这是唯一的问题。

Any help is highly appreciated.非常感谢任何帮助。 Many thanks in advance.提前谢谢了。 I hope, I gave all the relevant informations.我希望,我提供了所有相关信息。 If more information is needed, I'll provide that gladly.如果需要更多信息,我会很乐意提供。

You can install pytest with pip3 .您可以使用pip3 pytest For most libraries, pip3 defaults to python3.x and pip defaults to python2.x对于大多数库,pip3 默认为 python3.x,pip 默认为 python2.x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM