简体   繁体   English

当使用Python的pytest框架进行测试时,Pycharm会为测试生成奇怪的代码模板

[英]Pycharm generating weird code template for a test, when using Python's pytest framework for testing

Why is PyCharm generating the following code template, when clicking "Create New Test..:", even though I have pytest as my default test runner? 为什么PyCharm在单击“Create New Test ..:”时生成以下代码模板,即使我有pytest作为我的默认测试运行器?

If my function is create_training_data , then PyCharm will generate the following code for this: 如果我的函数是create_training_data ,那么PyCharm将为此生成以下代码:

from unittest import TestCase

class TestCreate_training_data(TestCase):
    def test_create_training_data(self):
    self.fail()

Yet pytest neither needs the import, nor the subclassing, having 然而, pytest既不需要导入,也不需要子类化

class TestCreate_training_data(object):
    def test_create_training_data(self):
    self.fail()

would be enough as already the getting started page shows: https://docs.pytest.org/en/latest/getting-started.html 已经足够的入门页面显示: https//docs.pytest.org/en/latest/getting-started.html

PyCharm only knows how to create unittest tests at the moment. PyCharm目前只知道如何创建unittest测试。 Please vote for the corresponding feature request: PY-15021 . 请投票支持相应的功能请求: PY-15021

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

相关问题 在 Python 中测试另一个线程的结果时,当断言应该失败时,PyTest 测试套件通过? - PyTest test-suite passing when asserts should fail when testing another thread's results in Python? 使用pytest使用奇怪的语法测试装饰器 - testing decorator with pytest using weird syntax 生成html表时的Python / Bottle模板怪异行为 - Python/Bottle template weird behavior when generating html table python中的测试函数,需要从用户那里获取输入并打印输出,使用pycharm和pytest - testing function in python that need to get input from user and print the output, using pycharm and pytest 为什么在使用 pytest-qt 进行测试时出现致命的 Python 错误? - Why a Fatal Python error when testing using pytest-qt? 在 PyCharm IDE 中使用 Python 的 Flask 框架创建 Web 应用程序时,如何创建模板来存储我的 HTML 文件? - How do I create a template to store my HTML file when creating a web app with Python's Flask Framework in the PyCharm IDE? Python - pycharm - 使用 OCR 代码时出错 - Python - pycharm - error when using OCR code 使用 pytest 时在哪里放置共享测试注释/代码? - Where to place shared test annotation/code when using pytest? 使用Pytest测试一个Python程序 - Using Pytest to test a Python Program 使用Pytest框架进行Argparse测试 - Argparse testing with Pytest framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM