pytest

`py.test` and `__init__.py` files

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I thought py.test is "standalone" in a sense that it treats test_*.py files "as it is", and only imports modules specified in these files, with no respect to any surrounding files. It looks like I'm wrong. Here is my dialog with py.test : $ ls __init__.py test_pytest.py $ cat __init__.py $ cat test_pytest.py def test_pytest(): assert True $ py.test test_pytest.py ========================================================= test session starts ========================================================== platform darwin -- Python 2.7.2 -- pytest-2

Using a command-line option in a pytest skip-if condition

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Long story short, I want to be able to skip some tests if the session is being run against our production API. The environment that the tests are run against is set with a command-line option. I came across the idea of using the pytest_namespace to track global variables, so I set that up in my conftest.py file. def pytest_namespace(): return {'global_env': ''} I take in the command line option and set various API urls (from a config.ini file) in a fixture in conftest.py. @pytest.fixture(scope='session', autouse=True) def configInfo

How do I Pytest a project using PEP 420 namespace packages?

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use Pytest to test a largish (~100k LOC, 1k files) project and there are several other similar projects for which I'd like to do the same, eventually. This is not a standard Python package ; it's part of a heavily customized system that I have little power to change, at least in the near term. Test modules are integrated with the code, rather than being in a separate directory, and that is important to us. The configuration is fairly similar to this question , and my answer there that might provide helpful background, too. The

pytest (py.test) very slow startup in cygwin

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: In cygwin, py.test starts up very slow. It does not look like a collection issue because of two reasons: The same test starts up quickly in linux. And sometimes, if rerun the same test fast enough in cygwin, it starts up in less than 1 second. Running through the time command tells it starts up in either 0.4 seconds, or 11.7 seconds, when supplied with the --collection-only option to avoid running the actual tests. I also added a print to the hooks pytest_configure() and pytest_ignore_collect() to be sure indeed it is before the

Debugging pytest post mortem exceptions in pycharm/pydev

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to use the built in Pytest runner of PyCharm together with the debugger without pre-configuring breakpoints. The problem is that exceptions in my test are caught by Pytest so PyCharm's post mortem debugger cannot handle the exception. I know using a breakpoint works but I would prefer not to run my test twice. Found a way to do this in Unittest, I would like to know if something like this exists in Pytest. Is there a way to catch unittest exceptions with PyCharm? 回答1: Are you using pytest-pycharm plugin? Looks like it works for

unittest Vs pytest

こ雲淡風輕ζ 提交于 2019-12-03 01:19:53
问题 In unittest, I can setUp variables in a class and then the methods of this class can chose whichever variable it wants to use... class test_class(unittest.TestCase): def setUp(self): self.varA = 1 self.varB = 2 self.varC = 3 self.modified_varA = 2 def test_1(self): do_something_with_self.varA, self.varB def test_2(self): do_something_with_self_modified_varA, self.varC So in unittest, it was easy to put bunch of tests together that could go under one class and then use many different variables

py.test -n <number of processes> => “py.test: error: unrecognized arguments: -n”

匿名 (未验证) 提交于 2019-12-03 00:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to distribute django tests to multiple processes to speed up test runs. I am using py.test in a virtual environment. My relevant versions are: $ pip freeze | grep test django-pytest==0.2.0 django-webtest==1.7.7 pytest==2.5.2 pytest-cov==1.6 pytest-django==2.6.2 pytest-xdist==1.10 scripttest==1.3 When I try the command: $ py.test -n 4 I get the error: usage: py.test [options] [file_or_dir] [file_or_dir] [...] py.test: error: unrecognized arguments: -n py.test traceconfig command shows: $ py.test --traceconfig PLUGIN registered: <

按书上学写测试pytest

匿名 (未验证) 提交于 2019-12-03 00:43:02
慢慢的,这块知识也补好吧。 系统的学习框架,具体的细节,可以边百度边实现。 test_three.py ‘‘‘ Test the Task data type . ‘‘‘ from collections import namedtuple Task = namedtuple ( ‘ Task ‘ , [ ‘ summary ‘ , ‘ owner ‘ , ‘ done ‘ , ‘ id ‘ ]) Task . __new__ . __defaults__ = ( None , None , False , None ) def test_defaults (): t1 = Task () t2 = Task ( None , None , False , None ) assert t1 == t2 def test_member_access (): t = Task ( ‘ buy milk ‘ , ‘ brian ‘ ) assert t . summary == ‘ buy milk ‘ assert t . owner == ‘ brian ‘ assert ( t . done , t . id ) == ( False , None ) ‘‘‘ Test the Task data type ‘‘‘ from collections import

pycharm运行Pytest警告:passing a string to pytest.main() is deprecated, pass a list of arguments instead.

匿名 (未验证) 提交于 2019-12-03 00:40:02
初学pytest. 将pytest写进Python代码中 不同运行方式都可正常运行 =======================**********************======================================= ============================================================================ 若是没有将pytest写进Python代码,直接运行的话将不能执行pytest: 没有将pytest写进Python代码,又想要执行Pytest,则需要选择py.test运行方式 原文:https://www.cnblogs.com/may18/p/9272203.html

pytest 基本用法

匿名 (未验证) 提交于 2019-12-03 00:13:02
1、断言用assert,可以进行==,!=,+,-,*,/,<=,>=,True,False,is True,is not True ,in ,not in 等判断。 2、测试文件和测试函数必须以“ test ”开头, 测试类 必须以‘ Test ’开头。 3、可以通过main()方法执行测试用例。需要指定参数和路径,还可以指定某个测试类或测试方法用“ :: ”隔开。如: pytest.main(['-s','./test_fixtures_01.py::test_multiply_5_6']) 4、Pytest提供了丰富的参数运行测试用例,‘-s’:关闭捕捉,输出打印信息。‘-v’:用于增加测试用例的冗长。‘-k’ 运行包含某个字符串的测试用例。如: pytest -k add XX.py 表示运行XX.py中包含add的测试用例。 ‘q’:减少测试的运行冗长。‘-x’:出现一条测试用例失败就退出测试。 在调试阶段非常有用,当测试用例失败时,应该先调试通过,而不是继续执行测试用例。 pytest还可以运行测试目录:pytest 目录 5、 来源:博客园 作者: 林深时见鹿 链接:https://www.cnblogs.com/wzjbg/p/11618515.html