18

In previous version of Nose testing framework, there were several ways to specify only a subset of all tests:

nosetests test.module
nosetests another.test:TestCase.test_method
nosetests a.test:TestCase
nosetests /path/to/test/file.py:test_function

http://nose.readthedocs.org/en/latest/usage.html#selecting-tests

However, I can't find any information about similar test selection in Nose2. There's a mention in docs about different test discovery, but that doesn't seem to be related.

Is there a way to select a specific test or test case in nose2 or (more generally) in unittest2?

Tomáš Ehrlich
  • 6,546
  • 3
  • 25
  • 31
  • [Here is a good doc page to get you running just certain tests.](https://nose2.readthedocs.org/en/latest/configuration.html) – yurisich Jul 26 '13 at 20:19
  • Well, that's not exactly what I'm looking for. The documentation is about configuring test discovery, not selecting specific test to run. It isn't convenient to modify config file each time I'd like to access different test. – Tomáš Ehrlich Jul 27 '13 at 06:10
  • Can you describe in more detail what your situation is like? I'm curious as to why you'd want to run your unit test in "chunks" like this, when you could just run the whole thing. – yurisich Jul 29 '13 at 13:47
  • 1
    I would like to run simple test during development, eg: when writing test or testcase, I would like to run it without running all bunch of tests (which could take several seconds/minutes). – Tomáš Ehrlich Jul 29 '13 at 20:59

3 Answers3

32

I have some tests in dev/tests, for example:

dev/tests/test_file.py

I am able to run this with:

nose2 -s dev tests.test_file

Additionally, I'm able to run a specific test method in a test case as follows:

nose2 -s dev tests.test_file.TestCase.test_method

Does that accomplish what you want?

jmagin
  • 690
  • 6
  • 9
  • Not obvious at first: `TestCase` should be whatever you named your `unittest.TestCase` subclass. – idbrii Nov 23 '20 at 23:18
1

Works without -s, if you have your test in tests/path/path2/mytest.py

You can do nose2 tests.path.path2.mytest

jvans
  • 2,765
  • 2
  • 22
  • 23
-1

You'd have to use a config file:

nose2 -c nose2.cfg

nose2.cfg:

[unittest]
start-dir=test/module

You'd probably want to just run all tests if you're considering writing a script that will modify that config file and re-run your nose tests. Unit tests should be pretty quick...but if you're just focusing on a specific section of tests, it's worth it to jump into this file and change that line during development.

yurisich
  • 6,991
  • 7
  • 42
  • 63