nose

Handling Exceptions in Python Behave Testing framework

你离开我真会死。 提交于 2019-12-10 03:34:02
问题 I've been thinking about switching from nose to behave for testing (mocha/chai etc have spoiled me). So far so good, but I can't seem to figure out any way of testing for exceptions besides: @then("It throws a KeyError exception") def step_impl(context): try: konfigure.load_env_mapping("baz", context.configs) except KeyError, e: assert (e.message == "No baz configuration found") With nose I can annotate a test with @raises(KeyError) I can't find anything like this in behave (not in the source

how to disable nose test's coverage report

醉酒当歌 提交于 2019-12-10 03:18:55
问题 Hopefully a simple python/django nose test question, though I can't find the answer in nose 's documentation. How do I stop the coverage report showing up after I run the tests with ./manage.py test ? I have a huge problem with the coverage report forcing me to scroll back a few dozen lines to get the traceback of my failing test, it really interrupts my workflow! I like using nose , but if I can't figure out how to get rid of this I'll have to go back to vanilla django tests. Thanks in

Conditional skip TestCase decorator in nosetests

混江龙づ霸主 提交于 2019-12-10 01:08:28
问题 Is there a way to skip whole TestCase based on custom condition using nosetests? I mean something in unittest.skip* style. I tried import unittest @unittest.skip("No reason") class TestFoo(object): def test_foo(self): assert False I found out this works using python <= 2.7.3 (apparently by accident), but in python 2.7.6 not. Is there a nosetests way to do this, or I have to create my own decorator? Notes: We tried all combinations of python 2.7.3, 2.7.6 and nosetests 1.1.2, 1.3.0. If the

Python 中如何实现参数化测试?

旧时模样 提交于 2019-12-09 22:34:25
之前,我曾转过一个单元测试框架系列的文章,里面介绍了 unittest、nose/nose2 与 pytest 这三个最受人欢迎的 Python 测试框架。 本文想针对测试中一种很常见的测试场景,即参数化测试,继续聊聊关于测试的话题,并尝试将这几个测试框架串联起来,做一个横向的比对,加深理解。 1、什么是参数化测试? 对于普通测试来说,一个测试方法只需要运行一遍,而参数化测试对于一个测试方法,可能需要传入一系列参数,然后进行多次测试。 比如,我们要测试某个系统的登录功能,就可能要分别传入不同的用户名与密码,进行测试:使用包含非法字符的用户名、使用未注册的用户名、使用超长的用户名、使用错误的密码、使用合理的数据等等。 参数化测试是一种“数据驱动测试”(Data-Driven Test),在同一个方法上测试不同的参数,以覆盖所有可能的预期分支的结果。它的测试数据可以与测试行为分离,被放入文件、数据库或者外部介质中,再由测试程序读取。 2、参数化测试的实现思路? 通常而言,一个测试方法就是一个最小的测试单元,其功能应该尽量地原子化和单一化。 先来看看两种实现参数化测试的思路:一种是写一个测试方法,在其内部对所有测试参数进行遍历;另一种是在测试方法之外写遍历参数的逻辑,然后依次调用该测试方法。 这两种思路都能达到测试目的,在简单业务中,没有毛病。然而,实际上它们都只有一个测试单元

What should a Python project structure look like for Travis CI to find and run tests?

天涯浪子 提交于 2019-12-09 18:11:43
问题 I currently have a project with the following .travis.yml file: language: python install: "pip install tox" script: "tox" Locally, tox properly executes and runs 35 tests, but on Travis CI, it runs 0 tests . More details: https://travis-ci.org/neverendingqs/pyiterable/builds/78954867 I also tried other ways, including: language: python python: - "2.6" - "2.7" - "3.2" - "3.3" - "3.4" - "3.5.0b3" - "3.5-dev" - "nightly" # also fails with just `nosetest` and no `install` step install: "pip

How to run nosetests without showing of my matplotlib's graph?

假装没事ソ 提交于 2019-12-09 17:41:00
问题 I try to run my test without any messages displaying from my main program. I only want verbose messages from nosetests to display. For example: nosetests -v --nologcapture All of my printout messages from my main program will be gone. However, the graph that I call in my main program ( plt.show() from matplotlib) still shows up. How do I run the tests without matplotlib's graph showing up? 回答1: I assume that you're calling unittests on your code, so my recommendation would be for you to

'nosetests' not recognized on Windows after being installed and added to PATH

六月ゝ 毕业季﹏ 提交于 2019-12-09 05:52:54
问题 I'm on exercise 46 of Learn Python the Hard Way, and I'm meant to install nose and run nosetests. I've installed nose already using pip, but when I run nosetests in the directory above the 'tests' folder, I get the error: 'nosetests' is not recognized as an internal or external command, operable program or batch file. If it's relevant, I've already modified the PATH variable to include full path of Python27/Scripts and Python/Lib/site-package . 回答1: If you are still having trouble after

Making the `nosetests` script select folder by Python version

核能气质少年 提交于 2019-12-08 18:00:51
问题 I used to have this in my setup.cfg file: [nosetests] where=test_python_toolbox But now I'm supporting Python 2 and Python 3 by supplying two parallel codebases, one in the source_py2 folder and one in the source_py3 folder. setup.py knows how to check the Python version and choose the correct one. Problem is, I don't know how to make nosetests , when invoked in the repo root, select the correct folder. I could have this: [nosetests] where=source_py2/test_python_toolbox But then tests would

PYTHON: nosetests import file path with multiple modules/files

≡放荡痞女 提交于 2019-12-08 16:43:34
I'm currently working through LearnPythonTheHardWay and have reached Exercise 48 which details Nosetests . I am able to perform a unit testing as long as all of the code is in a single python.py file. However if I include other files as part of a program, i.e. use import and then attempt to nosetest such a project I am getting an error, as follows: ====================================================================== ERROR: Failure: ImportError (No module named 'temp') Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/nose/failure.py", line 39, in runTest raise

simplest way of parameterizing tests in python?

混江龙づ霸主 提交于 2019-12-08 11:02:25
问题 I have a library with a bunch of different objects that have similar expected behavior, thus I want to run similar tests on them, but not necessarily identical tests on them. To be specific lets say I have some sorting functions, and a test for checking if a sorting function actually sorts. Some sorting functions are intended to work on some inputs, but not others. I'd like to write something close to the code below. However, nose won't do a good job of telling me exactly where the tests