0

I'm trying to start nosetests in programmatic way from my script

import nose nose.main()

or

import nose result = nose.run()

and it doesn't recognize my tests , when I use :

import subprocess subprocess.call('c:\somePath\nosetests-2.7.exe -w C:\MyProject -v -s ')

it works , my question is can I config somewhere nose.run() or nose.main() to use nosetests-2.7.exe

Chipopo
  • 47
  • 1
  • 9

2 Answers2

0

Are you sure the issue is with the wrong nosetests binary? What happens if you try

nose.run(argv="-w C:\MyProject -v -s".split())

and what error are you currently getting?

Vaibhav Sagar
  • 2,208
  • 15
  • 21
  • it runs , but it not recognize my tests , i made some experiments and what i found is if i use subprocess.call('c:\somePath\nosetests.exe -w C:\MyProject -v -s ') it doesnt recognize them , and if i use subprocess.call('c:\somePath\nosetests-2.7.exe -w C:\MyProject -v -s ') it works fine , i want the same result via programmatic way , i guess i should config somehow nosetests to use nosetests-2.7.exe – Chipopo Apr 18 '15 at 12:10
  • From [this answer](http://stackoverflow.com/questions/1457104/nose-unable-to-find-tests-in-ubuntu), what happens if you run `nose.run(argv="-vv --collect-only".split())`? – Vaibhav Sagar Apr 18 '15 at 12:36
  • 1
    And what happens if you rename `nosetests.exe` to `old_nosetests.exe` and `nosetests-2.7.exe` to `nosetests.exe` and then try `nose.run()`? – Vaibhav Sagar Apr 18 '15 at 12:38
  • still can't find the tests – Chipopo Apr 18 '15 at 12:40
  • i'll try to rename them now – Chipopo Apr 18 '15 at 12:41
  • well if i rename them it works , but i want a less hardcore solution :) – Chipopo Apr 18 '15 at 12:44
  • i renamed back , and restarted PyCharm and everything works now , very weird , tnx for your help – Chipopo Apr 18 '15 at 13:15
  • No worries, I was stuck because [the relevant source code](https://github.com/nose-devs/nose/blob/master/setup.py#L32-L33) seemed to suggest that both nosetests.exe and nosetests-2.7.exe were pointing to the same function and I was considering opening an issue, but I'm glad it's decided to work now. Very strange though. – Vaibhav Sagar Apr 18 '15 at 13:22
  • Dear @Vaibhav , i have another question for you :) how do i write the log to external file , tnx in advance – Chipopo Apr 18 '15 at 13:26
  • You should be able to supply any of the command line arguments in `argv`. Documentation is [here](http://nose.readthedocs.org/en/latest/usage.html#extended-usage). – Vaibhav Sagar Apr 18 '15 at 13:30
  • i read it 3 days already :) nothing about logging to file there – Chipopo Apr 18 '15 at 13:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75584/discussion-between-vaibhav-sagar-and-dima-rudaev). – Vaibhav Sagar Apr 18 '15 at 13:34
0

The first argument to the argv is always the process itself. So try something like:

   import sys
   import nose

   nose.run(argv=[sys.argv[0], 'C:\MyProject', '-s', '-v'])
Oleksiy
  • 6,337
  • 5
  • 41
  • 58