diff --git a/studyPyTest/conftest.py b/studyPyTest/conftest.py index 4a39b99..89fcbd6 100644 --- a/studyPyTest/conftest.py +++ b/studyPyTest/conftest.py @@ -4,7 +4,7 @@ # @Author : gonghuihui # @File : conftest.py import pytest - +import smtplib # content of conftest.py """ @@ -19,9 +19,8 @@ def image_file(tmpdir_factory): def test_histogram(image_file): img = load_image(image_file) # compute and test histogram -""" -""" + def test_func_fact(): print("fast") @@ -32,10 +31,21 @@ def test_func_slow_1(): @pytest.mark.xfail(not pytest.config.getoption("--runslow")) def test_func_slow_2(): print("xfail slow") -""" +""" from test_foocompare import Foo def pytest_assertrepr_compare(op, left, right): - if isinstance(left, Foo) and isinstance(left, Foo) and op == "==": + if isinstance(left, Foo) and isinstance(right, Foo) and op == "==": return ['Comparing Foo instance:', ' vals: %s != %s' %(left.val, right)] + + +# content of test_module +@pytest.fixture(scope="module") +def smtp(request): + server = getattr(request.module, "smtpserver", "smtp.mail.com") + smtp = smtplib.SMTP("smtp.gmail.com", 587, timeout=5) + yield smtp + print("finalizing %s (%s)" %(smtp, server)) + smtp.close() + diff --git a/studyPyTest/test_anothersmtp.py b/studyPyTest/test_anothersmtp.py new file mode 100644 index 0000000..86ff55a --- /dev/null +++ b/studyPyTest/test_anothersmtp.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-21 下午11:29 +# @Author : gonghuihui +# @File : test_anothersmtp.py + +smtpserver = "mail.python.org" +def test_showhelo(smtp): + assert 0,smtp.helo() \ No newline at end of file diff --git a/studyPyTest/test_module.py b/studyPyTest/test_module.py new file mode 100644 index 0000000..97852d0 --- /dev/null +++ b/studyPyTest/test_module.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-20 下午11:59 +# @Author : gonghuihui +# @File : test_module.py +def test_ehlo(smtp): + respone, msg = smtp.ehlo() + assert respone == 250 + assert b"smtp.gmail.com" in msg + assert 0 #for demo purpose 啥意思 + +def test_noop(smtp): + respone, msg = smtp.ehlo() + assert respone == 250 + assert 0 #for demo purpose \ No newline at end of file diff --git a/studyPyTest/test_smtpsimple.py b/studyPyTest/test_smtpsimple.py new file mode 100644 index 0000000..5e52000 --- /dev/null +++ b/studyPyTest/test_smtpsimple.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-20 下午10:46 +# @Author : gonghuihui +# @File : test_smtpsimple.py +import pytest + +@pytest.fixture() +def smtp(): + import smtplib + return smtplib.SMTP("smtp.gmail.com", 587, timeout=10) + +def test_ehlo(smtp): + response, msg = smtp.ehlo() + assert response == 250 + assert 0 +# 总是超时,为啥子嘞 \ No newline at end of file diff --git a/studyPyTest/test_yield2.py b/studyPyTest/test_yield2.py new file mode 100644 index 0000000..d572caa --- /dev/null +++ b/studyPyTest/test_yield2.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-21 下午10:48 +# @Author : gonghuihui +# @File : test_yield2.py +import pytest +import smtplib + +@pytest.fixture(scope="module") +def smtp(): + with smtplib.SMTP("smtp.gmail.com", 587, timeout=5) as smtp: + yield smtp #provide the fixture value