5 Claroja

尚未进行身份认证

我要认证

暂无相关简介

等级
TA的排名 269

python commandLine

usage: pytest [options] [file_or_dir] [file_or_dir] [...]positional arguments: file_or_dirgeneral: -k EXPRESSION only run tests which match the given substring expression. An expression is a python evaluatable

2020-07-03 21:59:24

python pytest 前置后置

有些函数需要连接数据库,可以把连接数据库和断开数据的操作放在,指定的函数里.这样每次测试函数的时候,都调取这个链接数据库的函数即可# test_db.py@pytest.fixture()def db(): print('Connection successful') yield print('Connection closed')def search_user(user_id): d = { '001': 'xiaoming' }

2020-07-03 21:59:05

python pytest mark.parametrize

虽然可以在测试函数内循环遍历所有参数的可能性,但一旦失败就终止了,即使try结果也比较南分析,所以可以使用pytest.mark.parametrize(argnames, argvalues)# test_parametrize.py@pytest.mark.parametrize('passwd', ['123456', 'abcdefdfs', 'as52345

2020-07-03 21:58:53

python pytest mark

默认情况下pytest会测试所有的函数,但是有些时候我们只想测试指定的函数,这就需要用到mark@pytest.mark.finished@pytest.mark.unfinished@pytest.mark.skip 跳过import pytest@pytest.mark.finisheddef test1_fun(): assert 1 == 1@pytest.mark.unfinisheddef test2_fun(): assert 1 == 1默认两个方法

2020-07-03 21:58:39

python pytest raises()

import pytestdef test_zero_division(): with pytest.raises(ZeroDivisionError) as excinfo://在该上下文下写跑一场的函数 1 / 0 assert excinfo.type == ZeroDivisionError # 断言异常类型type assert "division by zero" in str(excinfo.value) # 断言异常value值参考:

2020-07-03 21:58:23

python pytest

pytest命令会自动运行module中的以test_开头或者_test结尾的方法.test.pydef fun(): assert 1 == 1def test_fun(): assert 1 == 1PS D:\code\test> pytest test.py============================= test session starts =============================platform win32 -- Python

2020-07-03 21:58:10

click Utilities

Printing to StdoutANSI Colorsimport clickclick.echo(click.style('Hello World!', fg='green'))click.echo(click.style('Some more text', bg='blue', fg='white'))click.echo(click.style('ATTENTION', blink=True, bold=True))

2020-07-03 21:57:27

click Testing Click Applications

https://click.palletsprojects.com/en/7.x/testing/import click@click.command()@click.argument('name')def hello(name): click.echo('Hello %s!' % name)from click.testing import CliRunnerfrom hello import hellodef test_hello_world(): runner = Cli

2020-07-03 21:57:12

click Documenting Scripts

https://click.palletsprojects.com/en/7.x/documentation/option帮助信息help参数来填写帮助信息@click.command()@click.option('--count', default=1, help='number of greetings')@click.argument('name')def hello(count, name): """This script prints hello NAME COUNT tim

2020-07-03 21:56:57

click Arguments

https://click.palletsprojects.com/en/7.x/arguments/Arguments类似 options,但他的位置是固定的Basic Arguments@click.command()@click.argument('filename')def touch(filename): """Print FILENAME.""" click.echo(filename)Variadic Arguments@click.command()@cli

2020-07-03 21:56:48

click Commands and Groups

https://click.palletsprojects.com/en/7.x/commands/多个命令行可以嵌套@click.group()@click.option('--debug/--no-debug', default=False)def cli(debug): click.echo('Debug mode is %s' % ('on' if debug else 'off'))@cli.command() # @cli, not @click!def sync():

2020-07-03 21:56:28

click option

https://click.palletsprojects.com/en/7.x/options/Name Your OptionsA name is chosen in the following orderIf a name is not prefixed, it is used as the Python argument name and not treated as an option name on the command line.If there is at least on

2020-07-03 21:56:02

click Parameters

option is optionalarguments can be optional within reason

2020-07-03 21:55:49

click Setuptools Integration

https://click.palletsprojects.com/en/7.x/setuptools/介绍用click和setuptools自动生成命令行工程的结构如下:yourscript.pysetup.pyyourscript.pyimport click@click.command()def cli(): """Example script.""" click.echo('Hello World!')setup.pyfrom setuptools imp

2020-07-03 21:55:31

click quickstart

创建一个命令使用command()装饰后,方法就会成为命令行import click@click.command()def hello(): click.echo('Hello World!') # 使用echo是为了统一 python2 和 python3 的print,另外还可以添加颜色属性该方法被转换为一个命令if __name__ == '__main__': hello()在命令行中可以调用$ python hello.pyHello World!还可

2020-07-03 21:55:00

python-packaging 命令行脚本

setuptools可以将命令行工具添加到包中.有两种方法:1.scripts参数把命令工具卸载单独的文件中,一般放在bin目录下test/ test/ __init__.py ... setup.py bin/ test-test ...在setup.py中添加setup( ... scripts=['bin/test-test'], ...)2.console_scriptscon

2020-07-01 22:06:56

PythonEggs

http://peak.telecommunity.com/DevCenter/PythonEggs概览Eggs 之于 python,就像jar 之于Javapython eggs 将python工程和相关的信息进行打包,有一些二进制格式代表eggs,更常见的是.egg压缩格式.所有的格式都支持包含package-specific data, project-wide metadata, C extensions, and Python code.最简单安装egg的方法是使用Easy Install

2020-07-01 22:06:41

setuptools setup()

https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords参数描述nameA string specifying the name of the package.versionA string specifying the version number of the package.descriptionA string describing th

2020-07-01 22:06:12

setuptools find_packages

https://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packagesfind_packages当工程比较小的时候,可以通过packages参数来指定打包对象,当工程打的时候,就需要用到find_packages来自动打包find_namespace_packages()find_packages的替代,需要python 3.3+...

2020-07-01 22:05:57

setuptools Automatic Script Creation

https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation通过entry_point将模块的方法转换为命令行,缺点是不能传入参数

2020-07-01 22:05:38

查看更多

勋章 我的勋章
  • 签到新秀
    签到新秀
    累计签到获取,不积跬步,无以至千里,继续坚持!
  • 持之以恒
    持之以恒
    授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
  • 1024勋章
    1024勋章
    #1024程序员节#活动勋章,当日发布原创博客即可获得
  • 1024超级勋章
    1024超级勋章
    授予原创文章总数达到1024篇的博主,感谢你对CSDN社区的贡献,CSDN与你一起成长。
  • 勤写标兵Lv4
    勤写标兵Lv4
    授予每个自然周发布9篇以上(包括9篇)原创IT博文的用户。本勋章将于次周周三上午根据用户上周的博文发布情况由系统自动颁发。