craigahobbs / unittest-parallel

Parallel unit test runner for Python with coverage support
MIT License
29 stars 5 forks source link

Running a single test file given a file path #17

Closed bstaletic closed 9 months ago

bstaletic commented 9 months ago

I'm trying out unittest-parallel in my project.

I often do the following with unittest:

python -m unittest -cb path/to/test/file_test.py

The only way to do that with unittest-parallel seems to be

python -m unittest_parallel -b -k path.to.test.file_test -p '*_test.py'

which works fine, but is not as convenient to type manually, as bash/zsh can not help the user complete what is almost a file path (path separator is . and extension is dropped), but not really.

I am also aware that I can still use plain unittest for this use case, but I am wondering if I am just missing something obvious.

bstaletic commented 9 months ago

Another use case for file paths is this:

python -m unittest -cb path/to/first/group/*_test.py path/to/second/group/*_test.py

which I have used to select tests for testing under valgrind.

craigahobbs commented 9 months ago

Currently, unittest_parallel operates identically to "unittest discover." Consider your previous example (simplified):

python3 -m unittest -b path/to/first/group/*_test.py

This can also be run using "unittest discover" as follows:

python3 -m unittest discover -b -t path -s path/to/first/group

Running the tests using unittest_parallel is identical and drops the "discover" part, which is implicit:

python3 -m unittest_parallel -b -t path -s path/to/first/group

Unfortunately, "-s" doesn't support multiple paths, so your full example can't be run as-is (with first and second paths) - you'd need to run it as two commands:

python3 -m unittest_parallel -b -t path -s path/to/first/group
python3 -m unittest_parallel -b -t path -s path/to/second/group

I understand that this loses some of the value of parallelization. In your scenarios, how does this approach work for you?

bstaletic commented 9 months ago

Oh, I just figured out something!

python3 -m unittest_parallel -b -p sing_file_test.py -s path/to/test/dir

also works! I don't know why that did not occur to me before. Thanks for your answer.