How to run some test cases with specific attr in PyCharm?

已回答

This is my sample code.I write some cases for different language by attr. When I click Run, every case will be running. If I only want to run the cases with attr("python") in PyCharm, how can I do that?

from nose.plugins.attrib import attr
from nose.case import TestBase

class TestSample(TestBase):

    def setUp(self):
        print "setUp"

    def tearDown(self):
        print "tearDown"

    @attr("java")
    def test_java(self):
        print "test java"

    @attr("python")
    def test_python2(self):
        print "test python2"

    @attr("python")
    def test_python3(self):
        print "test python3"
0

Hi Rqycpp! Unfortunately there's no specific UI for this, but you can pass additional argument to test runner, in this particular case:

-a python

e.g.:

and it'll work as expected. More details can be found here: http://nose.readthedocs.io/en/latest/plugins/attrib.html

1
Avatar
Permanently deleted user

Hi Pavel Karateev! Thank you very much. You are very intelligent. It worked as my expected.

0

Could you please specify why do you use

from nose.case import TestBase

to base your tests on?

0
Avatar
Permanently deleted user

Hi Pavel Karateev! I'll explain this to you later. Now I have a new question about PyCharm. Can you help me?

I have a project, some test cases in a dir named `case`. Now I want to run all test cases in this path with nosetests. So I set nosetests configuration like this:

But when I click `Run`, there is no one test case be running. The result in console like this: 

If I not set `Additional Arguments` in `Configuration` like this:

All test cases will be running when I click `Run`. But I want to just run some case with attr("go"). 

Is it my fault? Thank you very much.

0

Hm, it works fine for me locally, could you please provide a sample test code that fails for you?

0
Avatar
Permanently deleted user

1. Set Configuration:

2. Sample test code and run result:

Thank you very much.

0

请先登录再写评论。