I have a folder structure:
app/
|
|-src/
| |
| |-Code.py
|
|-tests/
|
|-__init__.py
|-test_Code.py
I run my tests by issuing a command:
app$ python3 -m unittest discover
And as a result all my tests from test_Code.py
file are run.
I would like to run a single test from test_Code.py
file.
The contents of 'test_Code.py' are:
import unittest
from src.Code import Code
class TestCase1(unittest.TestCase):
def test_Code1(self):
...
def test_Code2(self):
...
if __name__ == '__main__':
unittest.main()
There is a question about running a single test: Running single test from unittest.TestCase via command line.
The answer given is:
python testMyCase.py MyCase.testItIsHot
which in my case would be (I think):
app$ python3 tests/test_Code.py TestCase1.test_Code1
Unfortunately this results in an error:
ImportError: No module named 'src'
There has been a comment that the proposed approach does not work, should the tests be in a subdirectory. A resolution is proposed:
python test/testMyCase.py test.MyCase.testItIsHot
I therefore try:
app$ python3 tests/test_Code.py test_Code.TestCase1.test_Code1
Which results in the same error.
I have also tried, among a couple of different things:
app$ python3 -m unittest tests/test_Code.py test_Code.TestCase1.test_Code1
But this runs all the tests.
The question is then: how to run a single test via a command line when tests are located within a sibling folder?