Created
September 5, 2014 08:58
-
-
Save huyx/7500d3afb35537c9c0f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
使用 py.test -s test_setup_teardown.py 运行 | |
""" | |
import os | |
def multiply(x, y): | |
return x * y | |
outputs = ["", "", "----"] | |
def setup_module(module): | |
outputs.append("setup_module module:%s" % module.__name__) | |
def teardown_module(module): | |
outputs.append("teardown_module module:%s" % module.__name__) | |
outputs.append("----") | |
print(os.linesep.join(outputs)) | |
def setup_function(function): | |
outputs.append("setup_function function:%s" % function.__name__) | |
def teardown_function(function): | |
outputs.append("teardown_function function:%s" % function.__name__) | |
def test_numbers_3_4(): | |
outputs.append(' test_numbers_3_4 <============================ actual test code') | |
assert multiply(3,4) == 12 | |
def test_strings_a_3(): | |
outputs.append(' test_strings_a_3 <============================ actual test code') | |
assert multiply('a',3) == 'aaa' | |
class TestUM: | |
def setup(self): | |
outputs.append("setup class:TestStuff") | |
def teardown(self): | |
outputs.append("teardown class:TestStuff") | |
def setup_class(cls): | |
outputs.append("setup_class class:%s" % cls.__name__) | |
def teardown_class(cls): | |
outputs.append("teardown_class class:%s" % cls.__name__) | |
def setup_method(self, method): | |
outputs.append("setup_method method:%s" % method.__name__) | |
def teardown_method(self, method): | |
outputs.append("teardown_method method:%s" % method.__name__) | |
def test_numbers_5_6(self): | |
outputs.append(' test_numbers_5_6 <============================ actual test code') | |
assert multiply(5,6) == 30 | |
def test_strings_b_2(self): | |
outputs.append(' test_strings_b_2 <============================ actual test code') | |
assert multiply('b',2) == 'bb' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment