????===================================================================
??????Python?????е???pytest
????pytest?????????main() ??????????в?????????
????pytest/
?????????? test_sample.py
?????????? test_class.py
?????????? test_main.py
????????????????????????test_mian.py
????import pytest
????def test_main():
????assert 5 != 5
????if __name__ == '__main__':
????pytest.main()
??????????иó???sublime ?а?Ctrl+B ???С???????£?
============================= test session starts =============================
platform win32 -- Python 2.7.10 -- py-1.4.30 -- pytest-2.7.2
rootdir: D:pysepytest?? inifile:
collected 4 items
test_class.py .F
test_main.py F
test_sample.py F
================================== FAILURES ===================================
_____________________________ TestClass.test_two ______________________________
self = <test_class.TestClass instance at 0x000000000304F548>
def test_two(self):
x = "hello"
>           assert x == "hi"
E           assert 'hello' == 'hi'
E             - hello
E             + hi
test_class.py:11: AssertionError
__________________________________ test_main __________________________________
def test_main():
>       assert 5 != 5
E    assert 5 != 5
test_main.py:4: AssertionError
_________________________________ test_answer _________________________________
def test_answer():
>       assert func(3) == 5
E    assert 4 == 5
E     +  where 4 = func(3)
test_sample.py:9: AssertionError
===================== 3 failed?? 1 passed in 0.03 seconds ======================
[Finished in 0.3s]
????????н????????main() ?????????????????????μ????в????????
??????????????????????????????????????????main()??????????????cmd??????????????????
????#coding=utf-8
????import pytest
????def test_main():
????assert 5 != 5
????if __name__ == '__main__':
????pytest.main("-q test_main.py")   # ??????????
???????н????
????F
????================================== FAILURES ===================================
????__________________________________ test_main __________________________________
????def test_main():
????>       assert 5 != 5
????E    assert 5 != 5
????test_main.py:4: AssertionError
????1 failed in 0.01 seconds
???????????????????????μ???????????????????????ɡ?
????#coding=utf-8
????import pytest
????def test_main():
????assert 5 != 5
????if __name__ == '__main__':
????pytest.main("d:/pyse/pytest/")  # ?????????
???????????в?????
?????????????????????????????????????£?????????е??????в???????????????α?д??????????в?????????????? pytest???????????????????????????
????>py.test --genscript=runtests.py

????????????runtests.py?????
sources = """
eNrsve2S3EiSIDa3+jhtnvZ293Ra6SSdCZMUF0AzK1nk9OzM1nV2L4dNznKnm6TxY6dX1XVJVAJV
halMIAkgWVU3O2d6Ar3CPYQeQn/1QjKTf8UnAplZ7O6ZPTNxpiszgQiPCA8PD3cPD/f/449+9/5H
yds/W99M58v6fDqfl1XZzefv/9nbvxuPxxE8Oy+r8+jRy2dREq+bOt8siqaNo6zKo3hRV+1mRb/h
a1UsuiKPPpRZdFncXNVN3qYRABmN3v/R23+OLbRd/v6/ePOf/tmPflSu1nXTRe1NOxotllnbRq+7
PKlPfwMw0qNR
……
"""
import sys
import base64
import zlib
class DictImporter(object):
def __init__(self?? sources):
self.sources = sources
def find_module(self?? fullname?? path=None):
if fullname == "argparse" and sys.version_info >= (2??7):
# we were generated with <python2.7 (which pulls in argparse)
# but we are running now on a stdlib which has it?? so use that.
return None
if fullname in self.sources:
return self
if fullname + '.__init__' in self.sources:
return self
return None
def load_module(self?? fullname):
# print "load_module:"??  fullname
from types import ModuleType
try:
s = self.sources[fullname]
is_pkg = False
except KeyError:
s = self.sources[fullname + '.__init__']
is_pkg = True
co = compile(s?? fullname?? 'exec')
module = sys.modules.setdefault(fullname?? ModuleType(fullname))
module.__file__ = "%s/%s" % (__file__?? fullname)
module.__loader__ = self
if is_pkg:
module.__path__ = [fullname]
do_exec(co?? module.__dict__) # noqa
return sys.modules[fullname]
def get_source(self?? name):
res = self.sources.get(name)
if res is None:
res = self.sources.get(name + '.__init__')
return res
if __name__ == "__main__":
if sys.version_info >= (3?? 0):
exec("def do_exec(co?? loc): exec(co?? loc) ")
import pickle
sources = sources.encode("ascii") # ensure bytes
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
else:
import cPickle as pickle
exec("def do_exec(co?? loc): exec co in loc ")
sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
importer = DictImporter(sources)
sys.meta_path.insert(0?? importer)
entry = "import pytest; raise SystemExit(pytest.cmdline.main())"
do_exec(entry?? locals()) # noqa
?????e??????? ??????????δ??????壬???????????????в??????????
????pytest/
?????????? test_case/
??????   ?????? test_sample.py
??????   ?????? test_class.py
??????   ?????? __init__.py
??????   ?????? test_case2/
??????          ?????? test_main.py
??????          ?????? test_time.py
??????          ?????? __init__.py
?????????? runtests.py
???????runtest.py?????
????>python runtest.py

?????????????????runtests.py ???????????
????===================================================================
????* ??pytest???????????????????????????ü????test_ *.py ??*_test.py???????????????????????????test_????????????????????????
????pytest???????????????????????????е????????????????