Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update conftest.py and insert test_module.py,test_smtpsimple.py #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions studyPyTest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# @Author : gonghuihui
# @File : conftest.py
import pytest

import smtplib
# content of conftest.py

"""
Expand All @@ -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")

Expand All @@ -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()

9 changes: 9 additions & 0 deletions studyPyTest/test_anothersmtp.py
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 15 additions & 0 deletions studyPyTest/test_module.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions studyPyTest/test_smtpsimple.py
Original file line number Diff line number Diff line change
@@ -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
# 总是超时,为啥子嘞
12 changes: 12 additions & 0 deletions studyPyTest/test_yield2.py
Original file line number Diff line number Diff line change
@@ -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