Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行单个测试的Python测试夹具?_Python_Unit Testing_Pytest_Nose - Fatal编程技术网

运行单个测试的Python测试夹具?

运行单个测试的Python测试夹具?,python,unit-testing,pytest,nose,Python,Unit Testing,Pytest,Nose,我正在寻找ruby rspec的focus元数据或elixir的混合标记之类的东西来运行单个python测试 Ruby RSpec示例: Elixir ExUnit和Mix示例: 这是否可能/可用于任何python测试运行程序和夹具组合?在大型项目中,通过命令行参数指定嵌套的module.class.test\u name来运行单个测试可能会变得非常冗长 比如: 所需的Python代码: 向……问好。您可以创建焦点标记,分配给任何测试用例或方法,然后使用pytest-v-mfocus命令运行测试

我正在寻找ruby rspec的
focus
元数据或elixir的混合标记之类的东西来运行单个python测试

Ruby RSpec示例: Elixir ExUnit和Mix示例: 这是否可能/可用于任何python测试运行程序和夹具组合?在大型项目中,通过命令行参数指定嵌套的
module.class.test\u name
来运行单个测试可能会变得非常冗长

比如:

所需的Python代码: 向……问好。您可以创建焦点标记,分配给任何测试用例或方法,然后使用
pytest-v-mfocus
命令运行测试。例如:

import unittest
import pytest

class TestOne(unittest.TestCase):
    def test_method1(self):
        # I won't be executed with focus mark
        self.assertEqual(1, 1)

    @pytest.mark.focus
    def test_method2(self):  
        # I will be executed with focus mark          
        self.assertEqual(1, 1)
将运行
测试方法2
。要在某个测试用例中运行所有方法,只需标记一个类:

import unittest
import pytest

@pytest.mark.focus
class TestOne(unittest.TestCase):
    ...
您需要在
pytest.ini
like中注册自定义标记

[pytest]
markers =
    focus: what is being developed right now
要查看可用标记,请运行
pytest--markers

import unittest
import pytest

class TestOne(unittest.TestCase):
    def test_method1(self):
        # I won't be executed with focus mark
        self.assertEqual(1, 1)

    @pytest.mark.focus
    def test_method2(self):  
        # I will be executed with focus mark          
        self.assertEqual(1, 1)
import unittest
import pytest

@pytest.mark.focus
class TestOne(unittest.TestCase):
    ...
[pytest]
markers =
    focus: what is being developed right now