Python 中未发现的单元测试 - Visual Studio Code [英] Unit Tests Not Discovered In Python - Visual Studio Code

查看:51
本文介绍了Python 中未发现的单元测试 - Visual Studio Code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 代码在 python 中编程,并且我正在尝试运行单元测试,但我的测试文件没有被发现.我收到以下消息:

I am using visual studio code to program in python and I am attempting to run unittests but my test files are not being discovered. I am getting the following message:

未发现测试,请检查测试的配置设置."

"No tests discovered, please check the configuration settings for the tests."

我的脚本(problem1.py)和我的测试脚本(problem1_test.py)在同一个目录下.我的设置配置如下:

My script (problem1.py) and my test script (problem1_test.py) are in the same directory. My settings are configured as follows:

{
"python.pythonPath": "C:\\Users\\Adam\\AppData\\Local\\Programs\\Python\\Python36\\python.exe",
"python.unitTest.unittestArgs": [
    "-v",
    "-s",
    ".",
    "-p",
    "*test.py"
],
"python.unitTest.unittestEnabled": true,
"python.unitTest.pyTestEnabled": false,
"python.unitTest.nosetestsEnabled": false,
"python.unitTest.promptToConfigure": false

}

不确定我是否遗漏了什么,任何帮助将不胜感激.

Not sure if I am missing something, any help would be appreciated.

推荐答案

我的解决方案可能无法解决您的问题,但解决了我的问题.有两个问题:

I have a solution that may not solve your problem but it fixed mine. There were two issues:

  1. 我的子目录中没有 ____init__.py.
  2. 我的派生测试类有一个函数定义错误.

我的派生单元测试类的定义有错误.就我而言,我有一个带有错误参数的 init 函数.当 VS 尝试查找单元测试时,它调用C:\Python36\lib\unittest\loader.py",最终在解析我的文件时给了我这个错误:

The definition for my derived unit test class had an error. In my case, I had an init function with the wrong parameters. When VS tries to find the unit tests it calls "C:\Python36\lib\unittest\loader.py" which ultimately gave me this error when parsing my files:

TypeError: __init__() takes 1 positional argument but 2 were given

我可以在 VS Code 底部的 OUTPUT 窗口选项卡中看到这一点.当我修复我的测试用例语法时,它找到了测试.

I could see this in the OUTPUT window tab at the bottom of VS Code. When I fixed my test case syntax it found tests.

这篇关于Python 中未发现的单元测试 - Visual Studio Code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆