From c02c207a4ccca2d930742a7807d1e18fad535ab4 Mon Sep 17 00:00:00 2001 From: gonghuihui55 Date: Wed, 13 Dec 2017 23:29:52 +0800 Subject: [PATCH 1/3] add_global_property.py --- requirement.txt | 2 ++ studyPyTest/add_global_property.py | 23 +++++++++++++++++++++++ studyPyTest/conftest.py | 20 ++++++++++++++++++++ studyPyTest/test_champ.py | 12 ++++++++++++ studyPyTest/test_class.py | 13 +++++++++++++ studyPyTest/test_tmpdir.py | 22 ++++++++++++++++++++++ 6 files changed, 92 insertions(+) create mode 100644 requirement.txt create mode 100644 studyPyTest/add_global_property.py create mode 100644 studyPyTest/conftest.py create mode 100644 studyPyTest/test_champ.py create mode 100644 studyPyTest/test_class.py create mode 100644 studyPyTest/test_tmpdir.py 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_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 From 47c0d80fbba277d583f690e43c70cf14c3c9aec8 Mon Sep 17 00:00:00 2001 From: gonghuihui55 Date: Thu, 14 Dec 2017 20:52:28 +0800 Subject: [PATCH 2/3] insert test_recursion_depth.py --- studyPyTest/test_recursion_depth.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 studyPyTest/test_recursion_depth.py diff --git a/studyPyTest/test_recursion_depth.py b/studyPyTest/test_recursion_depth.py new file mode 100644 index 0000000..57f4525 --- /dev/null +++ b/studyPyTest/test_recursion_depth.py @@ -0,0 +1,11 @@ +#!/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 From 9c00a0f1513e65ef718faaf0f8aa2605a406d249 Mon Sep 17 00:00:00 2001 From: gonghuihui55 Date: Thu, 14 Dec 2017 23:07:09 +0800 Subject: [PATCH 3/3] update test_recursion_depth --- .idea/vcs.xml | 6 ++++++ studyPyTest/test_recursion_depth.py | 1 + 2 files changed, 7 insertions(+) create mode 100644 .idea/vcs.xml 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/studyPyTest/test_recursion_depth.py b/studyPyTest/test_recursion_depth.py index 57f4525..a8a0e45 100644 --- a/studyPyTest/test_recursion_depth.py +++ b/studyPyTest/test_recursion_depth.py @@ -5,6 +5,7 @@ # @File : test_recursion_depth import pytest +#本来应该是执行失败的,可是执行成功了,为什么??? def test_recursion_depth(): with pytest.raises(ZeroDivisionError) as excinfo: 1/0