小编fin*_*mer的帖子

返回方法的 pytests 固定装置的类型提示

我的一些 pytest 固定装置返回一个方法。我想对我的所有方法使用类型提示。说一个方法返回一个我可以Callable在这里使用的方法。这里的问题是:我失去了 IDE PyCharm 中参数的自动完成功能。

没有给出夹具返回值的类型提示:

@pytest.fixture
def create_project():
    def create(location: Path, force: bool = True) -> bool:
        # ...

    return create


def test_project(create_project):
    project_created = create_project()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

使用给定的类型提示:

@pytest.fixture
def create_project() -> Callable[[Path, bool], bool]:
    def create(location: Path, force: bool = True) -> bool:
        # ...

    return create


def test_project(create_project):
    project_created = create_project()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

另一个问题Callable是,我必须在夹具中以及在我使用该夹具的每个测试中描述一次参数和返回类型。

那么有没有更有效的方法呢?

python pytest pycharm python-3.x

7
推荐指数
1
解决办法
832
查看次数

gnu并行:结合使用--pipe和args

使用--pipe -N<int>I 可以发送给定数量的行作为由 启动的作业的输入parallel:::但是我怎样才能运行多个作业,并在每个块上给出不同的参数呢?

让我们看一下这个小输入文件:

A   B   C
D   E   F
G   H   I
J   K   L
Run Code Online (Sandbox Code Playgroud)

此外,我们定义将每两行通过管道传输到一个parallel作业。cut -f<int>在它们上,应该使用作为并行输入参数给出的列号来执行命令,例如::: {1..3}

因此对于给定的示例,输出将如下所示

A
D
B
E
C
F
G
J
H
K
I
L
Run Code Online (Sandbox Code Playgroud)

我尝试过这个命令:

cat input.txt|parallel --pipe -N2 'cut -f{1}' ::: {1..3}
Run Code Online (Sandbox Code Playgroud)

但输出是这样的:

A
D
I
L
Run Code Online (Sandbox Code Playgroud)

我缺少什么?

鳍游泳者

bash gnu-parallel

4
推荐指数
1
解决办法
1429
查看次数

标签 统计

bash ×1

gnu-parallel ×1

pycharm ×1

pytest ×1

python ×1

python-3.x ×1