Пример #1
0
    def test_with(self):

        with mock.patch('module.give_me_five') as give_me_five:

            give_me_five.return_value = "I'm Mock"

            self.assertEqual(module.foo(), "I'm Mock")
Пример #2
0
    def test_module(self):

        module.give_me_five = mock.Mock(return_value=[1] * 5)

        module.give_me_five([1])  # 此时已经变成了一个Mock对象, 并尝试调用

        module.give_me_five.assert_called_with([1])  # 对mock的参数进行断言

        self.assertEqual(module.foo(), [1] * 5)
Пример #3
0
from module import foo

print(foo())
def test_foo():
    assert foo() == 'foo'
Пример #5
0
from module import foo, bar

foo("str")
foo(5)
foo(<warning descr="Unexpected type(s):(List[int])Possible type(s):(int)(str)">[5]</warning>)

bar("str")
bar(5)
bar(<warning descr="Unexpected type(s):(List[int])Possible type(s):(int)(str)">[5]</warning>)
Пример #6
0
from module import foo

foo()
Пример #7
0
# -*- coding: utf-8 -*-
"""
Created on Tue May 28 01:04:16 2019

@author: 井上菌
"""
'''
from module import foo
foo()


from module2 import foo
foo()'''

import module as m1
import module as m2

m1.foo()
m2.foo()
Пример #8
0
import logging
import time

from myLog import configure_logger

#配置logger,name為預設的'default'
#這行要放在其他需要logger的module前面
configure_logger(console_level=logging.INFO)

import module

#取得name為'default'的logger
logger = logging.getLogger('default')

logger.debug('main debug')
logger.warning('main warn')
logger.critical('main crit')

module.foo()

for i in range(15):
    logger.warning(i)
    time.sleep(0.5)