nose

pytest学习笔记

若如初见. 提交于 2021-02-16 13:22:59
pytest 优于其他测试框架的地方: 1、简单的测试可以简单的写 2、复杂的测试也可以简单的写 3、测试的可读性强 4、易于上手 5、断言失败仅使用原生assert关键字,而不是self.assertEqual()或者self.assertLessThan() 6、pytest可以运行有unitest和nose编写的测试用例 pytest不依赖python的版本,python2和3都能安装最新版的pytest Tasks项目: tasks程序通过CLI交互,底层编码通过调用API实现 很久没有更新博客园,比较好听点的原因是由于项目比较忙,没有时间整理写脚本过程中的问题。实际上是由本人的“懒”,不想写。不写不记录慢慢的就导致了懒癌的形成,久而久之某些知识回了之后就忘记了,好了 废话不多说 记录下最近写代码过程中的一些问题 1、写接口脚本时候,为了实现活动榜单数据制造,需要写一个登录方法 从json返回值中取出token、uid(uid 用来造主播榜单 给不同的主播送礼,token 不同用户给同一个主播送礼,造用户排行榜的榜单)。礼用config文件存储,将多个token从接口中读出存放在list,然后写入config.txt文件中,用来后面送礼 接口读取数据。但是发下config只能存入字符串str,于是后面想一个个的读取就失败了。 如果使用如下方法直接转换成list 不能实现

Is this the normal behavior of nosetests to pick only none executable .py?

有些话、适合烂在心里 提交于 2021-02-08 06:37:49
问题 Is this the normal behavior of nosetests to pick only none executable .py? Is there any alternatives to setup nosetests to pickup all .py in tests directory? Tree structure of the project: ├── __init__.py ├── lib │ ├── add_quiz.py │ ├── __init__.py │ └── take_quiz.py ├── README ├── setup.py └── tests ├── add_quiz_test.py ├── __init__.py ├── testCases └── testData Set permission as not executable, and the nosetests pickup the tests correctly [gliang@www quiz]$ chmod oug-x tests/add_quiz_test

How to get around “sys.exit()” in python nosetest?

北战南征 提交于 2021-02-07 11:22:49
问题 It seems that python nosetest will quit when encountered "sys.exit()", and mocking of this built-in doesn't work. Thanks for suggestions. 回答1: You can try catching the SystemExit exception. It is raised when someone calls sys.exit() . with self.assertRaises(SystemExit): myFunctionThatSometimesCallsSysExit() 回答2: import sys sys.exit = lambda *x: None Keep in mind that programs may reasonably expect not to continue after sys.exit() , so patching it out might not actually help... 回答3: If you're

How to get around “sys.exit()” in python nosetest?

牧云@^-^@ 提交于 2021-02-07 11:22:30
问题 It seems that python nosetest will quit when encountered "sys.exit()", and mocking of this built-in doesn't work. Thanks for suggestions. 回答1: You can try catching the SystemExit exception. It is raised when someone calls sys.exit() . with self.assertRaises(SystemExit): myFunctionThatSometimesCallsSysExit() 回答2: import sys sys.exit = lambda *x: None Keep in mind that programs may reasonably expect not to continue after sys.exit() , so patching it out might not actually help... 回答3: If you're

Get name of current test in setup using nose

回眸只為那壹抹淺笑 提交于 2021-02-07 06:56:43
问题 I am currently writing some functional tests using nose. The library I am testing manipulates a directory structure. To get reproducible results, I store a template of a test directory structure and create a copy of that before executing a test (I do that inside the tests setup function). This makes sure that I always have a well defined state at the beginning of the test. Now I have two further requirements: If a test fails, I would like the directory structure it operated on to not be

setting breakpoints with nosetests --pdb option

余生颓废 提交于 2021-02-05 12:38:48
问题 nosetests --pdb let's me halt upon error or failure, but this is too late for my needs. Stepping through code during execution helps me debug where the problem is. However, nosetests are helpful as they allow tests that rely on relative imports (i.e. tests in a package). How can I set breakpoints before the tests are executed? Currently I'm using: python -m pdb /path/to/my/nosetests testfile.py This solution isn't adequate. Nosetests interfere with pdb output, and my keyboard controls (e.g.

setting breakpoints with nosetests --pdb option

…衆ロ難τιáo~ 提交于 2021-02-05 12:38:25
问题 nosetests --pdb let's me halt upon error or failure, but this is too late for my needs. Stepping through code during execution helps me debug where the problem is. However, nosetests are helpful as they allow tests that rely on relative imports (i.e. tests in a package). How can I set breakpoints before the tests are executed? Currently I'm using: python -m pdb /path/to/my/nosetests testfile.py This solution isn't adequate. Nosetests interfere with pdb output, and my keyboard controls (e.g.

setting breakpoints with nosetests --pdb option

泪湿孤枕 提交于 2021-02-05 12:38:10
问题 nosetests --pdb let's me halt upon error or failure, but this is too late for my needs. Stepping through code during execution helps me debug where the problem is. However, nosetests are helpful as they allow tests that rely on relative imports (i.e. tests in a package). How can I set breakpoints before the tests are executed? Currently I'm using: python -m pdb /path/to/my/nosetests testfile.py This solution isn't adequate. Nosetests interfere with pdb output, and my keyboard controls (e.g.

setting breakpoints with nosetests --pdb option

送分小仙女□ 提交于 2021-02-05 12:38:05
问题 nosetests --pdb let's me halt upon error or failure, but this is too late for my needs. Stepping through code during execution helps me debug where the problem is. However, nosetests are helpful as they allow tests that rely on relative imports (i.e. tests in a package). How can I set breakpoints before the tests are executed? Currently I'm using: python -m pdb /path/to/my/nosetests testfile.py This solution isn't adequate. Nosetests interfere with pdb output, and my keyboard controls (e.g.

How do I use nosetests with a top-level directory as a package?

一世执手 提交于 2021-01-29 15:10:45
问题 This question shows a simple project: ./__init__.py ./foo.py ./tests ./__init__.py ./test_foo.py In my case, foo.py is an executable that also contains some functions imported by other code (say bar.py at the top level). The issue is that nose will not import packages from a top-level directory with an __init__.py. This answer says to either 1) remove the top-level __init__.py , or 2) change all the imports (including in foo.py if it imports from the top-level directory). I don't want to do 1