Skip to content
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
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions requirement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest >= 3.3
click >= 6.7
23 changes: 23 additions & 0 deletions studyPyTest/add_global_property.py
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions studyPyTest/conftest.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions studyPyTest/test_champ.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-10 下午10:19
# @Author : gonghuihui
# @File : test_champ.py


def func(x):
return x+1

def test_func():
assert func(2) == 3
13 changes: 13 additions & 0 deletions studyPyTest/test_class.py
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 12 additions & 0 deletions studyPyTest/test_recursion_depth.py
Original file line number Diff line number Diff line change
@@ -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'
22 changes: 22 additions & 0 deletions studyPyTest/test_tmpdir.py
Original file line number Diff line number Diff line change
@@ -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

#