【问题标题】:Pytest-3.3.2 using python 2.7Pytest-3.3.2 使用 python 2.7
【发布时间】:2018-11-10 16:48:37
【问题描述】:

我刚刚为 WSL 安装了 Ubuntu,主要是为了在我学习 Python 编码时能够使用 linux 命令,尤其是 git 和 pytest。 我使用 bash shell 安装了 pytest,即使我安装了 python 3.7,但在运行 pytest 时,它使用的是 python 2.7:

Python 2.7.15rc1、pytest-3.3.2

当从 windows CMD 运行 pytest 时,它运行的是不同版本的 pytest python 3.7

Python 3.7.0,pytest-3.10.0

我意识到这可能是一个非常愚蠢的问题,但这是我第一次涉足基于 linux 的应用程序,我想知道如何在 bash shell 中使用最新的 python 版本运行 pytest。我阅读了一些帖子并且已经尝试过:

python3 -m pytest

python3.7 -m pytest

但收到以下消息:

/usr/bin/python3: 没有名为 pytest 的模块

有人可以帮帮我吗?

谢谢

【问题讨论】:

    标签: ubuntu pytest windows-subsystem-for-linux


    【解决方案1】:

    谢谢

    事实上,我做了以下事情并且成功了:

    • apt install python 3 pip
    • sudo apt install python3-test

    之后调用pytest时会引用最新的python版本

    • python -m pytest -v

    【讨论】:

      【解决方案2】:

      首先检查系统中是否安装了pytest,通过给出命令: pytest -v。 如果它以以下方式返回: 平台 linux2 -- Python 2.7.17、pytest-3.3.2、py-1.5.2、pluggy-0.6.0 -- /usr/bin/python2

      表示 pytest 正在安装,但与当前版本的 python3 不匹配。

      要在系统上使用当前 Python3 版本运行: python -m pytest -v TestCases/Test_CreateUser.py

      其中 TestCases 是我的项目中的目录,并提供相应文件的路径以供运行。 以下是输出。

      平台 linux -- Python 3.6.9、pytest-5.4.1、py-1.8.1、pluggy-0.13.1 -- /home/rohitdalmia/PythonBasics/venv/bin/python 缓存目录:.pytest_cache 根目录:/home/rohitdalmia/PythonBasics 收集了 1 件物品

      TestCases/Test_CreateUser.py::test_create_new_user 已通过

      【讨论】:

        猜你喜欢
        • 2013-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-17
        • 2014-06-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多