nosetests

How to test that a function is called within a function with nosetests

风格不统一 提交于 2019-12-04 02:15:16
I'm trying to set up some automatic unit testing for a project. I have some functions which, as a side effect occasionally call another function. I want to write a unit test which tests that the second function gets called but I'm stumped. Below is pseudocode example: def a(self): data = self.get() if len(data) > 3500: self.b() # Bunch of other magic, which is easy to test. def b(self): serial.write("\x00\x01\x02") How do I test that b() -gets called? alecxe You can mock the function b using mock module and check if it was called. Here's an example: import unittest from mock import patch def a

How to access plugin options within a test? (Python Nose)

♀尐吖头ヾ 提交于 2019-12-03 22:16:35
问题 We are trying to implement an automated testing framework using nose. The intent is to add a few command line options to pass into the tests, for example a hostname. We run these tests against a web app as integration tests. So, we've created a simple plugin that adds a option to the parser: import os from nose.plugins import Plugin class test_args(Plugin): """ Attempting to add command line parameters. """ name = 'test_args' enabled = True def options(self, parser, env=os.environ): super

Append the nose @attr to the test name

孤街浪徒 提交于 2019-12-03 17:23:09
I am able to setup nose tests to run with the @attr tag. I am now interested in know if I can append to the end of the test name, the @attr tag? What we are trying to do is add a tag if our tests run into an issue and we write up a defect for it, we would then put the defect number as an @attr tag. Then when we run we could easily identify which tests have open defects against them. Just wondering if this is even possible, and where to go to see how to set it up? EDIT RESULTS RUNNING WITH ANSWER: Test Results: So I sort of know what is going on, if I have the @fancyattr() at the class level it

Can I restrict nose coverage output to directory (rather than package)?

走远了吗. 提交于 2019-12-03 11:15:17
问题 My SUT looks like: foo.py bar.py tests/__init__.py [empty] tests/foo_tests.py tests/bar_tests.py tests/integration/__init__.py [empty] tests/integration/foo_tests.py tests/integration/bar_tests.py When I run nosetests --with-coverage , I get details for all sorts of modules that I'd rather ignore. But I can't use the --cover-package=PACKAGE option because foo.py & bar.py are not in a package. (See the thread after http://lists.idyll.org/pipermail/testing-in-python/2008-November/001091.html

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

馋奶兔 提交于 2019-12-03 07:12:31
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 . If you are still having trouble after following Warren Weckesser's instructions try uninstalling and reinstalling. Using pip: pip uninstall nose I

How do I run a single test with Nose in Pylons

你离开我真会死。 提交于 2019-12-02 15:47:45
I have a Pylons 1.0 app with a bunch of tests in the test/functional directory. I'm getting weird test results and I want to just run a single test. The nose documentation says I should be able to pass in a test name at the command line but I get ImportErrors no matter what I do For example: nosetests -x -s sometestname Gives: Traceback (most recent call last): File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/loader.py", line 371, in loadTestsFromName module = resolve_name(addr.module) File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11

Using nose plugin to pass a boolean to my package

こ雲淡風輕ζ 提交于 2019-12-02 06:06:57
Can a variable be moved from the cmd to my module when using nose tests? Scenario: I am running tests with selenium that need to run against both production and sandbox versions of the website (www.sandbox.myurl.com and www.myurl.com) I wrote a custom nose plugin that lets me set which environment to run against EDITED CODE env = None class EnvironmentSelector(Plugin): """Selects if test will be run against production or sandbox environments. """ def __init__(self): Plugin.__init__(self) self.environment = "spam" ## runs against sandbox by default def options(self, parser, env): """Register

How can you suppress traces for failed test cases using Nose?

假如想象 提交于 2019-12-01 18:08:16
I'm writing a test suit with nose, and would like failing cases to display an output like "FAILED: is_even(5): Not even" instead of the default output: ====================================================================== FAIL: seed_db.test_generator(5,) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest self.test(*self.arg) File "/home/apurcell/tests/prism/seed_db.py", line 59, in is_even nose.tools.eq_(x % 2, 0, msg="Not even") File "/usr/local/lib/python2

How to access plugin options within a test? (Python Nose)

与世无争的帅哥 提交于 2019-12-01 00:24:45
We are trying to implement an automated testing framework using nose. The intent is to add a few command line options to pass into the tests, for example a hostname. We run these tests against a web app as integration tests. So, we've created a simple plugin that adds a option to the parser: import os from nose.plugins import Plugin class test_args(Plugin): """ Attempting to add command line parameters. """ name = 'test_args' enabled = True def options(self, parser, env=os.environ): super(test_args, self).options(parser, env) parser.add_option("--hostname", action="store", type="str", help=

Problems using nose in a virtualenv

独自空忆成欢 提交于 2019-11-30 10:54:11
问题 I am unable to use nose (nosetests) in a virtualenv project - it can't seem to find the packages installed in the virtualenv environment. The odd thing is that i can set test_suite = 'nose.collector' in setup.py and run the tests just fine as python setup.py test but when running nosetests straight, there are all sorts of import errors. I've tried it with both a system-wide installation of nose and a virtualenv nose package and no luck. Any thoughts? Thanks!! 回答1: Are you able to run myenv