nose

nose, unittest.TestCase and metaclass: auto-generated test_* methods not discovered

好久不见. 提交于 2019-11-26 19:54:43
问题 This is a follow-up question for unittest and metaclass: automatic test_* method generation: For this (fixed) unittest.TestCase layout: #!/usr/bin/env python import unittest class TestMaker(type): def __new__(cls, name, bases, attrs): callables = dict([ (meth_name, meth) for (meth_name, meth) in attrs.items() if meth_name.startswith('_test') ]) for meth_name, meth in callables.items(): assert callable(meth) _, _, testname = meth_name.partition('_test') # inject methods: test{testname}_v4,6

Nose unable to find tests in ubuntu

独自空忆成欢 提交于 2019-11-26 15:34:21
问题 Is there any reason why Nose wouldn't be able to find tests in Ubuntu 9.04? I'm using nose 0.11.1 with python 2.5.4. I can run tests only if I explicitly specify the filename. If I don't specify the filename it just says, 0 tests . The same project runs tests fine on my Mac, so I'm quite stumped! 回答1: Some what related, if you're running tests off of a directory i.e nosetests ... tests/ where tests is the name of the folder with my tests, and have separate python test functions in one of the

Scrapy Unit Testing

岁酱吖の 提交于 2019-11-26 12:52:55
问题 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 I\'d like to get nose working. Update: I\'ve been talking on Scrapy-Users and I guess I am supposed to \"build the Response in the test code, and then call the method with the response and assert that [I] get

Python Nose Import Error

徘徊边缘 提交于 2019-11-26 10:19:19
问题 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 True tests/test_foo.py contains: import foo def test_foo(): assert foo.dumb_true() Both init .py files are empty If I run nosetests -vv in the main

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

送分小仙女□ 提交于 2019-11-26 09:18:46
问题 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. 回答1: CAVEAT: I have no way of double checking the following theory at the moment, being away from a dev box. So this may be a shot in the dark. Perhaps you could check the return value of sys.exc_info() inside your tearDown() method, if it returns (None,