python - nose runs test on function in setUp when no suite specified -


i have tests file in 1 of pyramid projects. has one suite six tests in it:

... .scripts import populate_test_data  class functionaltests(unittest.testcase):      def setup(self):         settings = appconfig('config:testing.ini',                              'main',                              relative_to='../..')         app = main({}, **settings)         self.testapp = testapp(app)         self.config = testing.setup()         engine = engine_from_config(settings)         dbsession.configure(bind=engine)         populate_test_data(engine)      def teardown(self):         dbsession.remove()         teardown()      def test_index(self):         ...      def test_login_form(self):         ...      def test_read_recipe(self):         ...      def test_tag(self):         ...      def test_dish(self):         ...      def test_dashboard_forbidden(self):         ... 

now, when run nosetests templates.py (where templates.py mentioned file) following output:

......e ====================================================================== error: templates.populate_test_data ---------------------------------------------------------------------- traceback (most recent call last):   file "/home/yentsun/env/local/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/case.py", line 197, in runtest     self.test(*self.arg)   file "/home/yentsun/env/local/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/util.py", line 622, in newfunc     return func(*arg, **kw) typeerror: populate_test_data() takes 1 argument (0 given)  ---------------------------------------------------------------------- ran 7 tests in 1.985s  failed (errors=1) 

when run tests test suite specified nosetests templates.py:functionaltests, output is, expected, ok:

...... ---------------------------------------------------------------------- ran 6 tests in 1.980s  ok 

why have different output , why (7th) test run?

update. bit frustrating, when removed word test name populate_test_data (it became populate_dummy_data), worked fine.

the problem solved now, maybe knows went wrong here - why function setup had been tested?

finding , running tests

nose, default, follows few simple rules test discovery.

  • if looks test, it’s test. names of directories, modules, classes , functions compared against testmatch regular expression, , match considered tests. class unittest.testcase subclass collected, long inside of module looks test.

(from nose 1.3.0 documentation)

in nose's code, regexp defined r'(?:^|[\b_\.%s-])[tt]est' % os.sep, , if inpect nose/selector.py, method selector.matches(self, name) you'll see code uses re.search, looks match anywhere in string, not @ beginning, re.match does.

a small test:

>>> import re >>> import os >>> testmatch = r'(?:^|[\b_\.%s-])[tt]est' % os.sep >>> re.match(testmatch, 'populate_test_data') >>> re.search(testmatch, 'populate_test_data') <_sre.sre_match object @ 0x7f3512569238> 

so populate_test_data indeed "looks test" nose's standards.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -