diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/requirement.txt b/requirement.txt new file mode 100644 index 0000000..452877d --- /dev/null +++ b/requirement.txt @@ -0,0 +1,2 @@ +pytest >= 3.3 +click >= 6.7 \ No newline at end of file diff --git a/studyPyTest/add_global_property.py b/studyPyTest/add_global_property.py new file mode 100644 index 0000000..36d8014 --- /dev/null +++ b/studyPyTest/add_global_property.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-13 下午11:01 +# @Author : gonghuihui +# @File : add_global_property.py +import pytest + +@pytest.fixture(scope="session") +def log_global_env_facts(f): + + if pytest.config.pluginmanager.has_plugin('junit.xml'): + my_junit = getattr(pytest.config, '_xml', None) + + my_junit.add_golbal_property('ARCH', 'PPC') + my_junit.add_golbal_property('STORAGE_TYPE', 'CEPH') + +@pytest.mark.usefixtures(log_global_env_facts) +def start_and_prepare_evn(): + pass + +class TestMe(object): + def test_foo(self): + assert True \ No newline at end of file diff --git a/studyPyTest/conftest.py b/studyPyTest/conftest.py new file mode 100644 index 0000000..153f739 --- /dev/null +++ b/studyPyTest/conftest.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-13 下午10:24 +# @Author : gonghuihui +# @File : conftest.py +import pytest + +# content of conftest.py + +@pytest.fixture(scope='session') +def image_file(tmpdir_factory): + img = compute_expensive_image() + fn = tmpdir_factory.mktemp('data').join('img.png') + img.save(str(fn)) + return fn + +# contents of test_image.py +def test_histogram(image_file): + img = load_image(image_file) + # compute and test histogram \ No newline at end of file diff --git a/studyPyTest/test_champ.py b/studyPyTest/test_champ.py new file mode 100644 index 0000000..b82ead8 --- /dev/null +++ b/studyPyTest/test_champ.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-10 下午10:19 +# @Author : gonghuihui +# @File : test_champ.py + + +def func(x): + return x+1 + +def test_func(): + assert func(2) == 3 diff --git a/studyPyTest/test_class.py b/studyPyTest/test_class.py new file mode 100644 index 0000000..0479b4a --- /dev/null +++ b/studyPyTest/test_class.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-10 下午10:26 +# @Author : gonghuihui +# @File : test_class.py + +class TestClass: + def test_one(self): + assert "h" in "this" + + def test_two(self): + x = "hello" + assert hasattr(x,"check") \ No newline at end of file diff --git a/studyPyTest/test_recursion_depth.py b/studyPyTest/test_recursion_depth.py new file mode 100644 index 0000000..a8a0e45 --- /dev/null +++ b/studyPyTest/test_recursion_depth.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/12/14 20:31 +# @Author : yulu +# @File : test_recursion_depth +import pytest + +#本来应该是执行失败的,可是执行成功了,为什么??? +def test_recursion_depth(): + with pytest.raises(ZeroDivisionError) as excinfo: + 1/0 + assert excinfo.type == 'RuntimeError' \ No newline at end of file diff --git a/studyPyTest/test_tmpdir.py b/studyPyTest/test_tmpdir.py new file mode 100644 index 0000000..a00077e --- /dev/null +++ b/studyPyTest/test_tmpdir.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 17-12-13 下午9:51 +# @Author : gonghuihui +# @File : test_tmpdir.py + +import os + +# content of test_tempdir.py +def test_create_file(tmpdir): + p = tmpdir.mkdir("sub").join("hello.txt") + p.write("content") + assert p.read() == "content" + assert len(tmpdir.listdir()) == 1 +# assert 0 + +def test_needsfiles(tempdir): + print("*************") + print(tempdir) +# assert 0 + +# \ No newline at end of file