Python 单元测试如何将变量从一个函数传递到另一个函数

Python unit test how do I pass variable from one function to another

如何将变量从一个函数传递到另一个函数?喜欢:

def test_url(self):
    current_url = "xyz"
def check_url(self):
    #call current_url here.
def get_url(self):
    current_url = 'xyz'
    return current_url

def test_check_url(self):
    url = get_url()
    # write more lines

一个更好的方法是重载 unittest 附带的 setUp() 函数。 setUp() 为您完成初始化变量和测试的工作。

class YourTestCase(unittest.TestCase):
    def setUp(self):
        self.current_url = 'xyz'

    def test_check_url(self):
        self.assertEqual(self.current_url, 'xyz')