【问题标题】:VSCode Python test failing ERROR: file not found: ./test_mything_plugin.py::test_get_connVSCode Python 测试失败错误:找不到文件:./test_mything_plugin.py::test_get_conn
【发布时间】:2020-04-20 03:52:15
【问题描述】:

与 vscode-python github.com 问题列表中的 issue #8222 非常相似,但该线程似乎已死,所以我正在打开一个新线程

环境数据

VSCode 安装

Version: 1.39.2 (user setup)
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:35:18.241Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 6.1.7601

VSCode 远程 - SSH

我正在使用 VSCode Remote - SSH 在远程 linux 系统(版本 0.48.0)上进行所有开发和测试

VSCode 扩展

仅使用 VSCode Python 扩展 ms-python.python 版本 2019.11.50794 我曾经使用 python 测试扩展,但现在该功能已被吸收到 python 扩展中,这很棒

VSCode 项目设置.json

{
    "python.pythonPath": "/local/me/opt/miniconda3/envs/deathstar/bin/python",
    "python.testing.pytestArgs": [
        "test",
        "--disable-warnings",
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true,
}

Python

$ python --version
Python 3.6.8 :: Anaconda, Inc.

$ python -c "import pytest;print(pytest.__version__)"
5.3.1

预期行为

  1. VSCode 能够执行测试发现中所示的测试。
  2. VSCode 装饰显示在测试 .py 文件中

实际行为

  1. 测试发现有效,测试显示在测试资源管理器中,太棒了!
  2. 测试装饰不显示在文本编辑器窗口中
  3. 运行测试时,找不到已发现的测试文件,测试执行失败并在 DEBUG CONSOLE 中显示堆栈跟踪
============================= test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.3.1, py-1.8.1, pluggy-0.13.1
rootdir: /home/me/project/project_name
collected 0 items

-------------- generated xml file: /tmp/tmp-304736fTj9ikMPptk.xml --------------
============================== 1 warning in 0.01s ==============================
ERROR: file not found: ./test_mything_plugin.py::test_get_conn

输出

开发者工具控制台

[Extension Host] Info Python Extension: 2019-12-31 20:10:20: Cached data exists ActivatedEnvironmentVariables, /home/tjones/project/airflow_etl
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:10:20: getActivatedEnvironmentVariables, Class name = b, completed in 1ms, Arg 1: <Uri:/home/tjones/project/airflow_etl>, Arg 2: undefined, Arg 3: undefined
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:10:20: > /local/tjones/opt/miniconda3/envs/airflow/bin/python -m pytest --rootdir ~/project/airflow_etl --junitxml=/tmp/tmp-1575s6J3FtN4Ho55.xml --disable-warnings ./test_bam_ctds_plugin.py::test_get_conn
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:10:20: cwd: ~/project/airflow_etl

Python 输出

_当我点击调试按钮时,我什么也得不到,但是当我点击播放按钮时,我得到了这个

> /local/tjones/opt/miniconda3/envs/airflow/bin/python -m pytest --rootdir ~/project/airflow_etl --junitxml=/tmp/tmp-1575D8SX75zh6k5j.xml --disable-warnings ./test_bam_ctds_plugin.py::test_get_conn
cwd: ~/project/airflow_etl
> /local/tjones/opt/miniconda3/envs/airflow/bin/python -m pytest --rootdir ~/project/airflow_etl --junitxml=/tmp/tmp-1575s6J3FtN4Ho55.xml --disable-warnings ./test_bam_ctds_plugin.py::test_get_conn
cwd: ~/project/airflow_etl

【问题讨论】:

    标签: python visual-studio-code pytest


    【解决方案1】:

    通常情况下,用于测试的代码镜头会失败,因为另一个扩展程序干扰(例如 gitlens)或 IntelliSense 没有获取代码(例如 Jedi 或 Microsoft Python 语言服务器)。我会尝试关闭您的其他扩展程序,看看是否能解决问题。我还会检查您是否在测试文件中完成了代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      • 1970-01-01
      • 2019-10-03
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多