Re: [nose-users] Using xunit from a Python script - XML doesn't record any result

747 views
Skip to first unread message

prasanna

unread,
Apr 11, 2013, 11:55:50 AM4/11/13
to nose-...@googlegroups.com
On 11 April 2013 19:54, Leibo <assaf...@gmail.com> wrote:
> Hi,
>
> I have a file 'test_123' with a simple test:
>
> import unittest
>
> class Test1(unittest.TestCase):
> def test123(self):
> self.assertTrue(1 == 1)
>
>
> Next I'm trying to execute nose.run with the following code:
>
> import unittest
> from nose import run
> from nose.loader import TestLoader
>
> noseargs = ['', '--with-xunit', '--xunit-file=output.xml']
> tests_loaded = TestLoader().loadTestsFromName('test_123.py')
> run(suite = tests_loaded, argv=noseargs)
>
> Output XML:
>
> <?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="0"
> errors="0" failures="0" skip="0"></testsuite>
>
>
> output.xml is generated but all test counters are with '0', like it didn't
> run any test...
>
>
> Any idea?

One instance I've seen of the test runner skipping the selection of
your test case is when the test module has executable permissions. Are
you able to run the test without the xunit plugin? If yes - then the
problem is not with the permissions as was in my case.

Leibo

unread,
Apr 14, 2013, 1:54:18 AM4/14/13
to nose-...@googlegroups.com, t...@apache.org
Thanks... tried with and without exec permissions, still the XML contains no executable tests...

Leibo

unread,
Apr 14, 2013, 2:16:55 AM4/14/13
to nose-...@googlegroups.com, t...@apache.org
Hi,

I think I got it... 

I shouldn't suppose to pass a suite parameter but the test loader it self...

So the actual call is:

"run(tests_loaded, argv=noseargs)"

and NOT - "run(suite = tests_loaded, argv=noseargs)"

Leibo

unread,
Apr 14, 2013, 6:57:05 AM4/14/13
to nose-...@googlegroups.com, t...@apache.org
Well, not so fast...

Now the run method ignores my tests_loaded and just executes all tests found

Leibo

unread,
May 8, 2013, 1:20:48 PM5/8/13
to nose-...@googlegroups.com, t...@apache.org
Hi Katerina,

Well, our requirement is ro run specific tests in a specific directory.
So In the meantime, I execute the tests by calling the run method with the xunit arguments and the test file as the last argument.

This works great, we don't use the loader.

by the way, we also use a nice module called nose-testconfig (it will add the option to provide a config file as a nosetests parameter and use the same test with different configuration.)


On Wednesday, May 8, 2013 10:50:40 AM UTC+3, Katerina Romanchuk wrote:
oh!! yes, I have same problem :(

    argvs = ["nosetest",
             "--verbosity=2",
             "--with-xunit",
             "--with-id"]

    my_suite = nose.loader.TestLoader().discover('test_suites',pattern='*.py')
    result = nose.run(my_suite, argv=argvs)


run ALL TESTS IN ALL FOLDERS, not only from test_suites

nosetests.xml - is  CORRECT

-------------------------------
    my_suite = nose.loader.TestLoader().discover('test_suites',pattern='*.py')
    result = nose.run(argv=argvs, suite=my_suite)

run tests only from test_suites, but nosetests.xm is empty:

Katerina Romanchuk

unread,
May 10, 2013, 12:37:54 PM5/10/13
to nose-...@googlegroups.com, t...@apache.org
Good day!
Thank you for answer!


Ok, now I have test-suites structure look like these:

____________________________________________________

/nose_example

    /testdir_1
        tests.py

    /testdir_2
        tests.py

    run.py


run.py:

import nose
import sys

if __name__ == "__main__":

    argvs = ["nosetests",

         "--verbosity=2",
         "--with-xunit",
         "--with-id"]

    suite1 = nose.loader.TestLoader().discover('testdir_1',
                                                    pattern='*.py')

    nose.run(argv=argvs, suite=suite1)

____________________________________________________

I'm not very understand very well, please explain, if not hard. Have you proposed run specific tests in a specific directory like this?

/nose_example

    /testdir_1
        tests.py
        run_1.py


    /testdir_2
        tests.py
        run_2.py


run_1.py and run_2.py:

import nose
import sys

if __name__ == "__main__":

smoke_suite  = nose.loader.TestLoader().discover('testdir_1',pattern='*.py')
result = nose.run(smoke_suite, argv=["--verbosity=2", "--with-xunit", "--xunit-file=nosetests2.xml"])

____________________________________________________

Leibo

unread,
May 12, 2013, 1:49:15 AM5/12/13
to nose-...@googlegroups.com, t...@apache.org
Hi Katerina,

No, I just mentioned that we skip the whole test loading feature and just pass specific test file path to the nose.run method
Message has been deleted

Katerina Romanchuk

unread,
May 12, 2013, 3:32:25 AM5/12/13
to nose-...@googlegroups.com, t...@apache.org

Ok, I understand, thank you

vija...@dssd.com

unread,
Sep 27, 2015, 2:07:42 AM9/27/15
to nose-users, t...@apache.org
Hi,

Quick question: is there a way we can prevent or avoid or turn-off nose default discovery.. example,

from testSuite import Test1

          

class ApplianceTestSuite(unittest.TestCase):

   def test_suite(self):


        tests_loaded = TestLoader().loadTestsFromName(<>) 

        #`run(suite=tests_loaded) 


nose is executing all the tests from testSuite module before entering test_suite function... anyway to make nose avoid executing tests from testSuite...


Thanks,

vija...@dssd.com

unread,
Sep 27, 2015, 2:21:28 AM9/27/15
to nose-users, t...@apache.org
Hi,

I am facing same issue here, 
test_suite = loader.loadTestsFromModule(mod4)

when I specify run(test_suite, argv=argvs), nose is erroring out


when I specify run(suite=test_suite, argv=argvs), nose is executing but nosetests.xml is screwed..


not sure.. what is the right way...

Chris Withers

unread,
Sep 27, 2015, 2:25:04 AM9/27/15
to nose-...@googlegroups.com
On 27/09/2015 07:07, vija...@dssd.com wrote:
> Hi,
>
> Quick question: is there a way we can prevent or avoid or turn-off nose
> default discovery.. example,

http://nose.readthedocs.org/en/latest/finding_tests.html

> fromtestSuite importTest1
>
>
> class ApplianceTestSuite(unittest.TestCase):

__test__ = False

cheers,

Chris

vija...@dssd.com

unread,
Sep 27, 2015, 3:15:30 PM9/27/15
to nose-users
Thank you for your pointer, can we pass this flag on comman-line to nosetests command like,

/opt/tools/bin/nosetests --nocapture --nologcapture --with-xunit  --<another flag to stop auto-discovery>


Thank you once again,

Chris Withers

unread,
Sep 27, 2015, 4:08:04 PM9/27/15
to nose-...@googlegroups.com
Why don't you read the output of nosetests --help?
--
You received this message because you are subscribed to the Google Groups "nose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nose-users+...@googlegroups.com.
To post to this group, send email to nose-...@googlegroups.com.
Visit this group at http://groups.google.com/group/nose-users.
For more options, visit https://groups.google.com/d/optout.

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

Reply all
Reply to author
Forward
0 new messages