How to use func_no_arg method in assertpy

Best Python code snippet using assertpy_python

base_demo.py

Source:base_demo.py Github

copy

Full Screen

...12 def test_function(self):13 """测试函数"""14 # 函数中的第一个"""注释就是这个函数的doc15 print(func_no_arg.__doc__)16 func_no_arg()17 func_with_arg("arg1 value", "arg2 value")18 # 可以通过指定参数名传参19 func_with_arg(arg2="arg2 value", arg1="arg1 value")20 # 默认参数可以不传21 func_with_default_arg("arg value")22 # 默认参数传参可以覆盖默认值23 func_with_default_arg("arg value", "default value override")24 # 传任意参数,不能传关键字入参(入参指定参数名)25 func_with_any_arg("arg1 value", "arg2 value", 3)26 # 传入非关键字入参(入参不指定参数名)和关键字入参(入参指定参数名)27 func_args_keyword("arg1 value", "arg2 value", 3, k1="k1 value", k2=2)28 def test_function_annotation(self):29 """测试方法注解"""30 func_annnotation(1, -1)31 def test_dispatch(self):32 """分派"""33 func_obj("str")34class BaseDemo(unittest.TestCase):35 def test_global_var(self):36 """测试global"""37 func_global()38 # 非global的变量,python会在此作用域下,使用global的值创建一个同名的局部变量,此变量跟全局变量是两个变量39 no_use_global_var = "no_use_global_var override"40 # global的变量,就是跟全局的变量是同一个41 global global_var42 global_var = "global_var override"43 func_global()44 def test_non_local(self):45 """测试non_local"""46 non_local_var = "non_local_var"47 def inner_fun():48 # 表示此变量不是局部变量,也不是全局变量,用来修改外层函数的变量49 nonlocal non_local_var50 non_local_var = "non_local_var override"51 inner_fun()52 print(f"non_local_var:{non_local_var}")53 def test_exception(self):54 """测试异常"""55 func_exception(True)56 func_exception(False)57 def test_equal(self):58 class EqualClass:59 def __init__(self, value):60 self.value = value61 def __eq__(self, __o):62 print("__eq__")63 return self.value == __o.value64 a = EqualClass("value")65 b = EqualClass("value")66 # ==判断相等,调用__eq__方法67 self.assertTrue(a == b)68 # is判断是否是同一个对象69 self.assertFalse(a is b)70 def test_type(self):71 # isinstance判断是否属于指定类型72 print(f"isinstance:{isinstance(1,int)}")73 print(f"type is int {type(1) is int}")74 def test_with(self):75 """76 1. expression被执行得到返回值77 2. 调用返回值的__enter__方法78 3. __enter__的返回值赋值给target79 4. 执行with块80 5. 调用expression返回值的__exit__方法81 """82 with SimpleWith("without exception") as sw:83 print("do within without exception")84 with SimpleWith("with exception") as sw:85 print("do within with exceptioin")86 raise Exception87 # 如果__exit__返回False,则还会再抛出异常88 try:89 with SimpleWith("with exception exit False", False) as sw:90 print("do within with exceptioin exit False")91 raise Exception92 except BaseException:93 print("handle exception")94 def test_copy(self):95 """深复制和浅复制"""96 lst = [SimpleCopy("value")]97 # 浅复制98 shallow_copy = copy.copy(lst)99 shallow_copy[0].value = "simple_copy value"100 print(f"shallow copy:{lst[0].value}")101 # 深复制102 lst = [SimpleCopy("value")]103 deep_copy = copy.deepcopy(lst)104 deep_copy[0].value = "deep_copy value"105 print(f"deep copy:{lst[0].value}")106 def test_approximate(self):107 """近似"""108 # round(num[,n]):四舍五入,n表示小数位109 print(f"round:{round(1.336,2)}")110 # 格式化保留两位小数111 print("{:.2f}".format(321.33645))112class LoggerDemo(unittest.TestCase):113 def test_logging(self):114 """日志"""115 formatter = "%(asctime)s - %(levelname)s - %(message)s"116 logging.basicConfig(filename=curdir / "file/tmp/log.log", level=logging.DEBUG, format=formatter)117 logger = logging.getLogger()118 ch = logging.StreamHandler()119 ch.setFormatter(logging.Formatter(formatter))120 # 如果配置的是写入到文件的,默认不会输出到控制台,因此需要添加一个StreamHandler,把日志输入到控制台121 logger.addHandler(ch)122 logger.debug("test_logging message")123def func_no_arg():124 """不带参数"""125 print("func_no_arg")126def func_with_arg(arg1, arg2):127 """带参数"""128 print(f"func_with_arg, arg1:{arg1},arg2:{arg2}")129def func_with_default_arg(arg1, default_arg="default value"):130 """带默认参数"""131 print(f"func_with_default_arg, arg1:{arg1},default_arg:{default_arg}")132def func_with_any_arg(*args):133 """*args可以传任意参数,args是个tuple"""134 print(f"func_with_any_arg, args type:{type(args)}, args:{args}")135def func_args_keyword(*args, **kw):136 """带args和kw,args接受非关键字参数(入参不指定参数名),kw接收关键字参数(入参指定参数名),args是tuple,kw是dict"""137 print(f"func_args_keyword, args type:{type(args)},args:{args},kw type:{type(kw)},kw:{kw}")...

Full Screen

Full Screen

test_expected_exception.py

Source:test_expected_exception.py Github

copy

Full Screen

...109 "all err: arg1=a, arg2=b, args=(3, 4), kwargs=[('bar', 2), ('baz', 'dog'), ('foo', 1)]")110# helpers111def func_noop(*args, **kwargs):112 pass113def func_no_arg():114 raise RuntimeError('no arg err')115def func_one_arg(arg):116 raise RuntimeError('one arg err')117def func_multi_args(*args):118 raise RuntimeError('multi args err')119def func_kwargs(**kwargs):120 raise RuntimeError('kwargs err')121def func_all(arg1, arg2, *args, **kwargs):122 raise RuntimeError('all err: arg1=%s, arg2=%s, args=%s, kwargs=%s' % (arg1, arg2, args, [(k, kwargs[k]) for k in sorted(kwargs.keys())]))123class Foo(object):124 def bar(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful