nose

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

How to get around "sys.exit()" in python nosetest? Question: It seems that python nosetest will quit when encountered sys.exit(), and mocking of this builtin doesn’t work. Asked By: Hailiang Zhang || Source Answers: You can try catching the SystemExit exception. It is raised when someone calls sys.exit(). with self.assertRaises(SystemExit): myFunctionThatSometimesCallsSysExit() Answered By: kichik import sys …

Total answers: 5

How should we test exceptions with nose?

How should we test exceptions with nose? Question: I’m testing exceptions with nose. Here’s an example: def testDeleteUserUserNotFound(self): “Test exception is raised when trying to delete non-existent users” try: self.client.deleteUser(‘10000001-0000-0000-1000-100000000000’) # make nose fail here except UserNotFoundException: assert True The assert is executed if the exception is raised, but if no exception is raised, it …

Total answers: 6

Scrapy Unit Testing

Scrapy Unit Testing Question: I’d like to implement some unit tests in a Scrapy (screen scraper/web crawler). Since a project is run through the “scrapy crawl” command I can run it through something like nose. Since scrapy is built on top of twisted can I use its unit testing framework Trial? If so, how? Otherwise …

Total answers: 10

`python -m unittest discover` does not discover tests

`python -m unittest discover` does not discover tests Question: Python’s unittest discover does not find my tests! I have been using nose to discover my unit tests and it is working fine. From the top level of my project, if I run nosetests I get: Ran 31 tests in 0.390s Now that Python 2.7 unittest …

Total answers: 3

setting breakpoints with nosetests –pdb option

setting breakpoints with nosetests –pdb option Question: 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 …

Total answers: 4

Getting Python's unittest results in a tearDown() method

Getting Python's unittest results in a tearDown() method Question: Is it possible to get the results of a test (i.e. whether all assertions have passed) in a tearDown() method? I’m running Selenium scripts, and I’d like to do some reporting from inside tearDown(), however I don’t know if this is possible. Asked By: Joey Robert …

Total answers: 15

How do you run nosetest from pycharm?

How do you run nosetest from pycharm? Question: How do you execute nosetest from pycharm to run all unit tests? I know that pycharm supports python’s unittest and py.test and that they will properly support nosetests in pycharm 1.1 but I was wondering if there was a work around. Asked By: Nick Sonneveld || Source …

Total answers: 3

How to change the message in a Python AssertionError?

How to change the message in a Python AssertionError? Question: I’m writing per the following, in which I try to produce a decent error message when comparing two multiline blocks of Unicode text. The interior method that does the comparison raises an assertion, but the default explanation is useless to me I need to add …

Total answers: 4

Python Nose Import Error

Python Nose Import Error Question: I can’t seem to get the nose testing framework to recognize modules beneath my test script in the file structure. I’ve set up the simplest example that demonstrates the problem. I’ll explain it below. Here’s the the package file structure: ./__init__.py ./foo.py ./tests ./__init__.py ./test_foo.py foo.py contains: def dumb_true(): return …

Total answers: 9