Questions tagged [nose]

Nose is an alternate Python unittest discovery and running process. It is intended to mimic the behavior of py.test as much as is reasonably possible.

Nose is an alternate unittest discovery and running process. It is intended to mimic the behavior of py.test as much as is reasonably possible.

Resources

1036 questions
28
votes
3 answers

running nose --with-coverage to get all the package files, but not other dependencies and libs

My project folder(yeah - I know it's best practice) is something like: . ├── app.py ├── otherscript.py ├── tests/ └── tools/ ├── __init__.py └── toolfile.py I need nose --with-coverage to test the .py scripts in the main folder, tools…
alonisser
  • 11,542
  • 21
  • 85
  • 139
28
votes
1 answer

Python - How to unmock/reset mock during testing?

I'm using nosetests and in two separate files I have two tests. Both run fine when run individually, but when run together, the mock from the first test messes up the results in the second test. How do I insure that all mocks/patches are reset after…
golmschenk
  • 11,736
  • 20
  • 78
  • 137
26
votes
2 answers

Run all Tests in Directory Using Nose

I need to be able to run all tests in the current directory by typing one line in the Linux shell. In some directories, this works fine. But in others, when I type "nosetests" no tests are run. The tests will run if I call for them individually but…
Matt
  • 1,021
  • 4
  • 16
  • 25
26
votes
3 answers

How to mock generators with mock.patch

I have gone through the page https://docs.python.org/3/library/unittest.mock-examples.html and i see that they have listed an example on how to mock generators I have a code where i call a generator to give me a set of values that i save as a…
akshitBhatia
  • 1,131
  • 5
  • 12
  • 20
25
votes
1 answer

Nose ignores test with custom decorator

I have some relatively complex integration tests in my Python code. I simplified them greatly with a custom decorator and I'm really happy with the result. Here's a simple example of what my decorator looks like: def specialTest(fn): def…
Corey Coogan
  • 1,569
  • 2
  • 17
  • 31
24
votes
2 answers

I need a sample of python unit testing sqlalchemy model with nose

Can someone show me how to write unit tests for sqlalchemy model I created using nose. I just need one simple example. Thanks.
RobertVa
  • 259
  • 1
  • 2
  • 5
24
votes
3 answers

Python nosetests with coverage no longer shows missing lines

I've been using the following command to run tests and evaluate code coverage for a Python project for over a year now. nosetests -v --with-coverage --cover-package=genhub genhub/*.py The coverage report used to include a column on the far right…
Daniel Standage
  • 8,136
  • 19
  • 69
  • 116
22
votes
2 answers

How can I access variables set in the Python nosetests setup function

I think what I'm trying to do is fairly simple. I want to initialize a couple of variables in a test setup function, and then use them in the test functions that are decorated with that setup. The following trivial example illustrates what I…
Mark Tozzi
  • 10,353
  • 5
  • 22
  • 30
21
votes
4 answers

Why not use python's assert statement in tests, these days?

In Python testing, why would you use assert methods: self.assertEqual(response.status_code, 200) self.assertIn('key', my_dict) self.assertIsNotNone(thing) As opposed to the direct assertions: assert response.status_code == 200 assert 'key' in…
wim
  • 338,267
  • 99
  • 616
  • 750
21
votes
3 answers

Excluding directory, module in python nosetest

We use nose to discover tests and run them. All the tests are written in TestCase compatible way so any test runner can run the. Problem is we have some directories which doesn't have any test. But test runner continue to discover test from there.…
Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
20
votes
8 answers

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

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…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
20
votes
5 answers

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

It seems that python nosetest will quit when encountered sys.exit(), and mocking of this builtin doesn't work.
Hailiang Zhang
  • 17,604
  • 23
  • 71
  • 117
20
votes
2 answers

How does django-nose differ from the default Django test-runner

I've been seeing and reading about a lot of people using nose to run their Django tests. I haven't been able to figure out the added benefits of using Nose to run my Django tests. If someone could fill me in on what nose is and how it adds more to a…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
20
votes
2 answers

Nose Test Generators inside Class

Is it possible to run nose test generators inside custom classes? I am trying to convert the example into a simple class based version: file: trial.py >>>>>>>>>>>>>> class ATest(): def test_evens(self): for i in range(0, 5): …
Longestline
  • 270
  • 2
  • 9
20
votes
2 answers

How to run Python nose tests with a different version of Python

We have CentOS with the ancient Python 2.4 interpreter. But we would like to write out tests with a newer 2.5/2.6 syntax. Assuming we have a second Python interpreter installed (e.g. python2.6) is there any way to run the 'nosetests' shell command…
Jacek Furmankiewicz
  • 1,143
  • 1
  • 13
  • 22
1 2
3
69 70