简体   繁体   中英

unit test runs with python but fails with nosetests

I have written a python file containing some unit tests (testfile.py).

When I run 'python testfile.py' the tests run fine and there are no errors.

But when I run 'nosetests testfile.py', I get a TypeError of the form TypeError: func_name() takes exactly 3 arguments (1 given).

Can you please help me understand what might be going on and how can I modify the python file so that it can be run using both python and nosetests. Thanks in advance, Ambarish.

Yeah, you're getting hung on how discovery works differently on the different tools. It trips me up all the time. Go into the directory with your tests and do:

$ nosetests testfile

(no .py on the end of testfile)

You can also use the python unittest module:

$ python -m unittest testfile

I figured out what the problem was. I had a non-test function which included 'test' in its name even it id did not start with 'test_', as a result of which it was treated as a test function by nose. When I modified the name of the function, the problem was solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM