FAQ Database Discussion Community


unittest vs pytest vs nose [closed]

python,nose,py.test,python-unittest
I'm new in python testing and am having some diffiulties choosing between unittest, pytest and nose nose. I'm bulding a test lib that requires : installing a package changing the conf restarting deamons and unsintalling the packages on a linux box. Which test framewok will be the best between thoses...

Python unit tests: TestCaseSource

django,unit-testing,nose
I am new to python development, specifically Django pipeline. I am used to nunit testing framework where I have tools such as the TestCaseData class. we are currently using the nose framework with the django.test modules. heres my question: is there a module or some component that does the same...

Can't get Nose to honor the attributes I set on my tests

python,django,testing,nose,django-nose
I'm using Django 1.7 with django-nose 1.4 and nose 1.3.6. According to the documentation, I should be able to select tests to be run by using attributes. I have a test set like this: from nose.plugins.attrib import attr from django_webtest import TransactionWebTest @attr(isolation="menu") class MenuTestCase(TransactionWebTest): def test_home(self): pass When I...

Why does import work with Python nose when test directory contains __init__.py?

python,nose
Consider the following project structure: a.py test/ test_a.py with test_a.py importing module a: import a As expected, running nosetests in the test directory results in import error: ERROR: Failure: ImportError (No module named a) However, I noticed that adding an empty __init__.py file to the test directory makes import work...

use class method in nose parameterize.expand call

nose,nose-parameterized
I have a generator method that is building a large set of test criteria, I know i can make a non class method to be called, but I much rather have the parameter building method be part of my test class. is there a way to do this? here is...

How to run tests in order of their appearance in test script using nose?

nose,py.test,nosetests,python-unittest,python-nose
I want run my tests in order of they are written not in alphabetical order that unittest does by default. import unittest class test2(unittest.TestCase): def test1(self): pass def test0(self): pass class test1(unittest.TestCase): def testB(self): pass def testA(self): pass In this example I want to set unittest or nosetests to run...

Python - String with timestamp changing

python,python-2.7,timestamp,python-import,nose
I'm attempting to initialize a string variable in Python using the datetime package. I expect that string to stay the same once it's been initialized, but for some strange reason (at least strange to me), it's changing. Essentially, when I attempt: timestamp = datetime.datetime.now().strftime('%m-%d-%Y.%I_%M_%S_%p') base_directory = "C:\\Users\\Ben\\report_" + timestamp +...

How to use nosetests in python while also passing/accepting arguments for argparse?

python,nose,coverage.py
I want to use nose and coverage in my project. When I run nose with --with-coverage argument, my programs argument-parsing module goes nuts because "--with-coverage" isn't a real argument according to it. How do I turn the argparse off, but during testing only? Nose says all my tests fail because...

Setting PYTHONPATH with bash script and running nosetests

python,bash,nose
I have the following script that sets a clean PYTHONPATH: #!/bin/bash # Get the directory the script is in DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) $ Walk up to root of branch dir DIR=$DIR/../../.. PYTHONPATH=$DIR/module1 PYTHONPATH=$PYTHONPATH:$DIR/module2 PYTHONPATH=$PYTHONPATH:$DIR/module3 PYTHONPATH=$PYTHONPATH:$DIR/module4 export PYTHONPATH This script is supposed to be run in tandem...

Test a abstract class in Python

python,unit-testing,nose
I created a class by using the abstract class in Python(2.7) and now I want to test this class by Nose. How to implement it technically? Here I give an example code: # -*- coding: utf-8 -*- from abc import ABCMeta, abstractmethod, abstractproperty class A(object): __metaclass__ = ABCMeta @abstractproperty def...

nosetests pip install error on python 3.4 in a virtualenv

python-3.x,pip,nose
Upgrading app from python 2.7 to 3.4 and nose is generating the following error: Collecting nose==1.3.4 (from -r requirements/dev.txt (line 9)) Exception: Traceback (most recent call last): File "/Users/me/.virtualenvs/python3.4/lib/python3.4/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/Users/me/.virtualenvs/python3.4/lib/python3.4/site-packages/pip/commands/install.py", line 339, in run requirement_set.prepare_files(finder) File...

How do I run pytest on all-modules?

python,nose,py.test
nose has an all-modules=1 configuration value which makes its test collector look in all files, not just the ones following its naming conventions: .http://nose.readthedocs.org/en/latest/plugins/allmodules.html What is the equivalent way to do this with pytest? i.e. I do not want to rename all our test modules when switching to pytest....

Why does Python2.7 insist on Python3 print statement?

python-2.7,python-3.x,numpy,nose,nosetests
I was trying to see how nose & unittesting were being used in a package I'm learning about. This package uses nosetester, which is provided with numpy (why this is done also confuses me). My nosetester.py is in /usr/local/lib/python2.7/dist-packages/numpy/testing/. I am running Python 2.7.6. However, when I add a tracing...

Using iPython with nose?

python,ipython,nose,pdb
I have a fairly basic question. I'm running the nosetests command for my python application's test suite. I want to drop into an interactive debugger. As the tests are run, it hits my IPython.embed() line and freezes, no prompt. Ctrl+C kills it and resumes the tests. How can I drop...

turning off coverage in nosetests

python,code-coverage,nose
How do I conditionally turn off coverage when running nosetests? there is a --with-coverage flag that doesn't seem to do all that much. It certainly does not turn off coverage. Mind you, I like coverage and I want to keep it. I just find it extremely distracting to see its...

nose reports cumulative coverage

python,unit-testing,testing,nose
Image a situation where you have a BASE_CLASS. Several class inherits from that class: CHILD_A, CHILD_B, CHILD_C. Now let us write unit tests, but ONLY for CHILD_A, CHILD_B, CHILD_C. I would suspect, that the coverage for BASE_CLASS is 0%. Unfortunately, nose takes cumulative coverage, which is not what I want....

python cross platform testing: mocking os.name

python,testing,mocking,nose
what is the correct way to mock os.name? I am trying to unittest some cross-platform code that uses os.name to build platform-appropriate strings. I am running on a Windows machine but want to test code that can run on either posix or windows. I've tried: production_code.py from os import name...

How can I unit test when code throws an ImportError?

python,unit-testing,nose,nosetests
I have a Python module that tries to import a module, and if it fails, adds sets up a lightweight class to replicate some of the functionality as a fallback. How can I write a unit test that covers both cases - when the module is present, and when the...

Nose does not run tests

python,nose,nosetests
Suppose you have a python package named A with the following directory structure A ├── B.py └── __init__.py where __init__.py is empty and the content of B.py is given by def test_B(): assert False Running nose on the simple package above misses the test $ nosetests A ---------------------------------------------------------------------- Ran 0...

Error running nosetests

python,nose
I recently reinstalled nose to run tests on my code. https://nose.readthedocs.org/en/latest/ I used sudo pip install nose and went to my project folder. The response is -bash: nosetests: command not found. So, I once again I uninstalled and tried installing nose with MacPorts: sudo port install py27-nose In my project...