Only run a specific test

View: New views
8 Messages — Rating Filter:   Alert me  

Only run a specific test

by Nikolaus Rath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

Is it possible to run only a specific test function from a testcase?

I tried to run the following file

,----
| import unittest
|
| class Test(unittest.TestCase):
|
|     def test_one(self):
|         self.assertTrue(1+1 == 2)
|        
|     def test_two(self):
|         self.assertTrue(1+1 == 3)    
|
| if __name__ == "__main__":
|     unittest.main()
`----
   
with a custom-run configuration derived from "Python unit-test" where I
set the arguments to "Test.test_one" (or just "test_one"). But instead
of running only the first test, this produces the following error in the
console:

,----
| Traceback (most recent call last):
|   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 257, in <module>
|     PydevTestRunner(dirs, test_filter, verbosity).run_tests()
|   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 69, in __init__
|     self.__adjust_path()
|   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 86, in __adjust_path
|     raise RuntimeError(msg)
| RuntimeError: unknown type.
| Test.test_one
| should be file or a directory.
`----



Best,

   

   -Nikolaus

--
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pydev-users mailing list
Pydev-users@...
https://lists.sourceforge.net/lists/listinfo/pydev-users

Re: Only run a specific test

by Fabio Zadrozny-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Usually, what I do to run only one test is setting the main part to:

if __name__ == '__main__':
    import sys;sys.argv=['', 'Test.test_one']
    unittest.main()

You could also do a suite and call that suite, but I find that way
easier (and yes, pydev should have a better support to run only one
method from a test case... can you create a feature request for that?)

Cheers,

Fabio

On Tue, Jun 9, 2009 at 8:20 PM, Nikolaus Rath<Nikolaus@...> wrote:

> Hello,
>
> Is it possible to run only a specific test function from a testcase?
>
> I tried to run the following file
>
> ,----
> | import unittest
> |
> | class Test(unittest.TestCase):
> |
> |     def test_one(self):
> |         self.assertTrue(1+1 == 2)
> |
> |     def test_two(self):
> |         self.assertTrue(1+1 == 3)
> |
> | if __name__ == "__main__":
> |     unittest.main()
> `----
>
> with a custom-run configuration derived from "Python unit-test" where I
> set the arguments to "Test.test_one" (or just "test_one"). But instead
> of running only the first test, this produces the following error in the
> console:
>
> ,----
> | Traceback (most recent call last):
> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 257, in <module>
> |     PydevTestRunner(dirs, test_filter, verbosity).run_tests()
> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 69, in __init__
> |     self.__adjust_path()
> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 86, in __adjust_path
> |     raise RuntimeError(msg)
> | RuntimeError: unknown type.
> | Test.test_one
> | should be file or a directory.
> `----
>
>
>
> Best,
>
>
>
>   -Nikolaus
>
> --
>  »Time flies like an arrow, fruit flies like a Banana.«
>
>  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Pydev-users mailing list
> Pydev-users@...
> https://lists.sourceforge.net/lists/listinfo/pydev-users
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pydev-users mailing list
Pydev-users@...
https://lists.sourceforge.net/lists/listinfo/pydev-users

Re: Only run a specific test

by Nikolaus Rath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

But why isn't your method equivalent to specifying the argument in the
custom-run configuration? I thought that everything that I enter there
is simply passed on to sys.argv of my Python program...

Best,

-Nikolaus


Fabio Zadrozny <fabiofz@...> writes:

> Usually, what I do to run only one test is setting the main part to:
>
> if __name__ == '__main__':
>     import sys;sys.argv=['', 'Test.test_one']
>     unittest.main()
>
> You could also do a suite and call that suite, but I find that way
> easier (and yes, pydev should have a better support to run only one
> method from a test case... can you create a feature request for that?)
>
> Cheers,
>
> Fabio
>
> On Tue, Jun 9, 2009 at 8:20 PM, Nikolaus Rath<Nikolaus@...> wrote:
>> Hello,
>>
>> Is it possible to run only a specific test function from a testcase?
>>
>> I tried to run the following file
>>
>> ,----
>> | import unittest
>> |
>> | class Test(unittest.TestCase):
>> |
>> |     def test_one(self):
>> |         self.assertTrue(1+1 == 2)
>> |
>> |     def test_two(self):
>> |         self.assertTrue(1+1 == 3)
>> |
>> | if __name__ == "__main__":
>> |     unittest.main()
>> `----
>>
>> with a custom-run configuration derived from "Python unit-test" where I
>> set the arguments to "Test.test_one" (or just "test_one"). But instead
>> of running only the first test, this produces the following error in the
>> console:
>>
>> ,----
>> | Traceback (most recent call last):
>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 257, in <module>
>> |     PydevTestRunner(dirs, test_filter, verbosity).run_tests()
>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 69, in __init__
>> |     self.__adjust_path()
>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 86, in __adjust_path
>> |     raise RuntimeError(msg)
>> | RuntimeError: unknown type.
>> | Test.test_one
>> | should be file or a directory.
>> `----
>>
>>
>>
>> Best,
>>
>>
>>
>>   -Nikolaus
>>
>> --
>>  »Time flies like an arrow, fruit flies like a Banana.«
>>
>>  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
>>
>>
>> ------------------------------------------------------------------------------
>> Crystal Reports - New Free Runtime and 30 Day Trial
>> Check out the new simplified licensing option that enables unlimited
>> royalty-free distribution of the report engine for externally facing
>> server and web deployment.
>> http://p.sf.net/sfu/businessobjects
>> _______________________________________________
>> Pydev-users mailing list
>> Pydev-users@...
>> https://lists.sourceforge.net/lists/listinfo/pydev-users
>>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects


   -Nikolaus

--
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pydev-users mailing list
Pydev-users@...
https://lists.sourceforge.net/lists/listinfo/pydev-users

Re: Only run a specific test

by Fabio Zadrozny-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> But why isn't your method equivalent to specifying the argument in the
> custom-run configuration? I thought that everything that I enter there
> is simply passed on to sys.argv of my Python program...


Hi,

Yes, it's the same... It's just that I usually find it more convenient
to edit it there.

Cheers,

Fabio


> Best,
>
> -Nikolaus
>
>
> Fabio Zadrozny <fabiofz@...> writes:
>> Usually, what I do to run only one test is setting the main part to:
>>
>> if __name__ == '__main__':
>>     import sys;sys.argv=['', 'Test.test_one']
>>     unittest.main()
>>
>> You could also do a suite and call that suite, but I find that way
>> easier (and yes, pydev should have a better support to run only one
>> method from a test case... can you create a feature request for that?)
>>
>> Cheers,
>>
>> Fabio
>>
>> On Tue, Jun 9, 2009 at 8:20 PM, Nikolaus Rath<Nikolaus@...> wrote:
>>> Hello,
>>>
>>> Is it possible to run only a specific test function from a testcase?
>>>
>>> I tried to run the following file
>>>
>>> ,----
>>> | import unittest
>>> |
>>> | class Test(unittest.TestCase):
>>> |
>>> |     def test_one(self):
>>> |         self.assertTrue(1+1 == 2)
>>> |
>>> |     def test_two(self):
>>> |         self.assertTrue(1+1 == 3)
>>> |
>>> | if __name__ == "__main__":
>>> |     unittest.main()
>>> `----
>>>
>>> with a custom-run configuration derived from "Python unit-test" where I
>>> set the arguments to "Test.test_one" (or just "test_one"). But instead
>>> of running only the first test, this produces the following error in the
>>> console:
>>>
>>> ,----
>>> | Traceback (most recent call last):
>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 257, in <module>
>>> |     PydevTestRunner(dirs, test_filter, verbosity).run_tests()
>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 69, in __init__
>>> |     self.__adjust_path()
>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 86, in __adjust_path
>>> |     raise RuntimeError(msg)
>>> | RuntimeError: unknown type.
>>> | Test.test_one
>>> | should be file or a directory.
>>> `----
>>>
>>>
>>>
>>> Best,
>>>
>>>
>>>
>>>   -Nikolaus
>>>
>>> --
>>>  »Time flies like an arrow, fruit flies like a Banana.«
>>>
>>>  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Crystal Reports - New Free Runtime and 30 Day Trial
>>> Check out the new simplified licensing option that enables unlimited
>>> royalty-free distribution of the report engine for externally facing
>>> server and web deployment.
>>> http://p.sf.net/sfu/businessobjects
>>> _______________________________________________
>>> Pydev-users mailing list
>>> Pydev-users@...
>>> https://lists.sourceforge.net/lists/listinfo/pydev-users
>>>
>>
>> ------------------------------------------------------------------------------
>> Crystal Reports - New Free Runtime and 30 Day Trial
>> Check out the new simplified licensing option that enables unlimited
>> royalty-free distribution of the report engine for externally facing
>> server and web deployment.
>> http://p.sf.net/sfu/businessobjects
>
>
>   -Nikolaus
>
> --
>  »Time flies like an arrow, fruit flies like a Banana.«
>
>  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Pydev-users mailing list
> Pydev-users@...
> https://lists.sourceforge.net/lists/listinfo/pydev-users
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pydev-users mailing list
Pydev-users@...
https://lists.sourceforge.net/lists/listinfo/pydev-users

Re: Only run a specific test

by Nikolaus Rath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Fabio Zadrozny <fabiofz@...> writes:
>> But why isn't your method equivalent to specifying the argument in the
>> custom-run configuration? I thought that everything that I enter there
>> is simply passed on to sys.argv of my Python program...
>
> Yes, it's the same... It's just that I usually find it more convenient
> to edit it there.

Well, it's apparently not quite the same. As I wrote in my first email,
if I enter it into the configuration, it produces an error:

>>>> I tried to run the following file
>>>>
>>>> ,----
>>>> | import unittest
>>>> |
>>>> | class Test(unittest.TestCase):
>>>> |
>>>> |     def test_one(self):
>>>> |         self.assertTrue(1+1 == 2)
>>>> |
>>>> |     def test_two(self):
>>>> |         self.assertTrue(1+1 == 3)
>>>> |
>>>> | if __name__ == "__main__":
>>>> |     unittest.main()
>>>> `----
>>>>
>>>> with a custom-run configuration derived from "Python unit-test" where I
>>>> set the arguments to "Test.test_one" (or just "test_one"). But instead
>>>> of running only the first test, this produces the following error in the
>>>> console:
>>>>
>>>> ,----
>>>> | Traceback (most recent call last):
>>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 257, in <module>
>>>> |     PydevTestRunner(dirs, test_filter, verbosity).run_tests()
>>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 69, in __init__
>>>> |     self.__adjust_path()
>>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 86, in __adjust_path
>>>> |     raise RuntimeError(msg)
>>>> | RuntimeError: unknown type.
>>>> | Test.test_one
>>>> | should be file or a directory.
>>>> `----


Best,



   -Nikolaus

--
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pydev-users mailing list
Pydev-users@...
https://lists.sourceforge.net/lists/listinfo/pydev-users

Re: Only run a specific test

by Fabio Zadrozny-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jun 10, 2009 at 8:50 PM, Nikolaus Rath<Nikolaus@...> wrote:
> Fabio Zadrozny <fabiofz@...> writes:
>>> But why isn't your method equivalent to specifying the argument in the
>>> custom-run configuration? I thought that everything that I enter there
>>> is simply passed on to sys.argv of my Python program...

Actually, if you do it like that you have to run it as a regular run
(and not as a unit-test run).

Cheers,

Fabio



>>
>> Yes, it's the same... It's just that I usually find it more convenient
>> to edit it there.
>
> Well, it's apparently not quite the same. As I wrote in my first email,
> if I enter it into the configuration, it produces an error:
>
>>>>> I tried to run the following file
>>>>>
>>>>> ,----
>>>>> | import unittest
>>>>> |
>>>>> | class Test(unittest.TestCase):
>>>>> |
>>>>> |     def test_one(self):
>>>>> |         self.assertTrue(1+1 == 2)
>>>>> |
>>>>> |     def test_two(self):
>>>>> |         self.assertTrue(1+1 == 3)
>>>>> |
>>>>> | if __name__ == "__main__":
>>>>> |     unittest.main()
>>>>> `----
>>>>>
>>>>> with a custom-run configuration derived from "Python unit-test" where I
>>>>> set the arguments to "Test.test_one" (or just "test_one"). But instead
>>>>> of running only the first test, this produces the following error in the
>>>>> console:
>>>>>
>>>>> ,----
>>>>> | Traceback (most recent call last):
>>>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 257, in <module>
>>>>> |     PydevTestRunner(dirs, test_filter, verbosity).run_tests()
>>>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 69, in __init__
>>>>> |     self.__adjust_path()
>>>>> |   File "/home/nikratio/lib/eclipse/plugins/org.python.pydev.debug_1.4.6.2788/pysrc/runfiles.py", line 86, in __adjust_path
>>>>> |     raise RuntimeError(msg)
>>>>> | RuntimeError: unknown type.
>>>>> | Test.test_one
>>>>> | should be file or a directory.
>>>>> `----
>
>
> Best,
>
>
>
>   -Nikolaus
>
> --
>  »Time flies like an arrow, fruit flies like a Banana.«
>
>  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Pydev-users mailing list
> Pydev-users@...
> https://lists.sourceforge.net/lists/listinfo/pydev-users
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pydev-users mailing list
Pydev-users@...
https://lists.sourceforge.net/lists/listinfo/pydev-users

Re: Only run a specific test

by Nikolaus Rath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Fabio Zadrozny <fabiofz@...> writes:
> On Wed, Jun 10, 2009 at 8:50 PM, Nikolaus Rath<Nikolaus@...> wrote:
>> Fabio Zadrozny <fabiofz@...> writes:
>>>> But why isn't your method equivalent to specifying the argument in the
>>>> custom-run configuration? I thought that everything that I enter there
>>>> is simply passed on to sys.argv of my Python program...
>
> Actually, if you do it like that you have to run it as a regular run
> (and not as a unit-test run).

Hmm. So these error messages are intended behavior? Or am I not supposed
to enter any arguments into unit-test runs? (in that case, why does
pydev allow me to do so in the first place?)


Best,


   -Nikolaus

--
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pydev-users mailing list
Pydev-users@...
https://lists.sourceforge.net/lists/listinfo/pydev-users

Re: Only run a specific test

by Fabio Zadrozny-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Jun 11, 2009 at 12:01 AM, Nikolaus Rath<Nikolaus@...> wrote:

> Fabio Zadrozny <fabiofz@...> writes:
>> On Wed, Jun 10, 2009 at 8:50 PM, Nikolaus Rath<Nikolaus@...> wrote:
>>> Fabio Zadrozny <fabiofz@...> writes:
>>>>> But why isn't your method equivalent to specifying the argument in the
>>>>> custom-run configuration? I thought that everything that I enter there
>>>>> is simply passed on to sys.argv of my Python program...
>>
>> Actually, if you do it like that you have to run it as a regular run
>> (and not as a unit-test run).
>
> Hmm. So these error messages are intended behavior? Or am I not supposed
> to enter any arguments into unit-test runs? (in that case, why does
> pydev allow me to do so in the first place?)
>

The only arguments accepted in a unit-test run right now are the
folders/files with the tests to run (so, you can add/edit arguments,
but those must currently map to folders/files to run) -- although this
will change to accept running only some of the wanted tests.

Cheers,

Fabio

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pydev-users mailing list
Pydev-users@...
https://lists.sourceforge.net/lists/listinfo/pydev-users