Pytest: document test if style output of --collect-only output with -q

Created on 6 Mar 2018  路  20Comments  路  Source: pytest-dev/pytest

Currently the --collect-only option shows the collected tests in a tree style presentation.
I was wondering if there is a way to show the collected tests list with the -v style, of course without the test result.
This would be useful to compare the output of --collect-only with the output of other runs of the tests.

easy needs information docs

Most helpful comment

thats supported with -q for just test ids and -qq for just test filenames

All 20 comments

It is not quite clear to me what you mean @fontealpina, would you mind add more details? Thanks!

Let's suppose to have a test:

class TestSuite():

    def test_case_01(self):
        assert True

    def test_case_02(self):
        assert True

Running the test with pytest -v the output is:

collected 2 items                                                                                                                                                                                                                       

test_path/test.py::TestSuite::test_case_01 PASSED
test_path/test.py::TestSuite::test_case_02 PASSED

====================== 2 passed in 0.01 seconds =======================

Running pytest with pytest --collect-only the output is:

collected 2 items                                                                                                                                                                                                                       
<Module 'test.py'>
  <Class 'TestSuite'>
    <Instance '()'>
      <Function 'test_case_01'>
      <Function 'test_case_02'>

==================== no tests ran in 0.00 seconds =====================

I was wondering how it would be possible instead to get with pytest --collect-only an output like:

collected 2 items                                                                                                                                                                                                                       

test_path/test.py::TestSuite::test_case_01 
test_path/test.py::TestSuite::test_case_02
==================== no tests ran in 0.00 seconds =====================

That seems useful to easily copy test IDs to select individual tests too.

thats supported with -q for just test ids and -qq for just test filenames

@RonnyPfannschmidt Thanks

closing as it seems to be answered

Thx @fontealpina for creating this ticket! Is this documented in our docs? If not, we should change that.

@thisch I have just checked and actually seems it is missing.

in that case it should be added, thanks for going and checking

I would expect that the test items returned by pytest --collect-only -qq can be passed as arguments to pytest, but it turns out that this does not work (neither pytest "tests/test_a.py::TestXYZ::test_abc" nor pytest -k "tests/test_a.py::TestXYZ::test_abc" works)

Do you know if this is supported by using different cmd line flags?

drop the -k and it should work, those are nto valid keywords, they are node ids

oh, and if it doesn't ,thats a bug

@thisch it works for me using -q:

位 pytest foo.py -q --collect-only
foo.py::test1[0]
foo.py::test1[1]
foo.py::test1[2]
foo.py::test1[3]
foo.py::test1[4]
foo.py::test1[5]
foo.py::test1[6]
foo.py::test1[7]
foo.py::test1[8]
foo.py::test1[9]
位 pytest foo.py::test1[4] -v
================================================= test session starts =================================================
platform win32 -- Python 2.7.12, pytest-3.4.0, py-1.5.2, pluggy-0.6.0 -- w:\ws\Souring\envs\souring20-py27\python.exe
cachedir: .pytest_cache
PyQt5 5.5.1 -- Qt runtime 5.5.1 -- Qt compiled 5.5.1
rootdir: w:\ws\Souring\Projects\souring\souring20, inifile: pytest.ini
plugins: xdist-1.22.0, timeout-1.2.1, replay-0.2.2, qt-2.1.0, mock-1.6.3, localserver-0.4.1, lazy-fixture-0.3.0, forked-0.2, cpp-0.4.5, cov-2.5.1, llvmpipe-gl-0.0.0
collected 1 item

foo.py::test1[4] PASSED                                                                                          [100%]

============================================== 1 passed in 0.15 seconds ===============================================

Or do you really mean -qq? If that's the case indeed it does not produce usable ids:

位 pytest foo.py -qq --collect-only
foo.py: 10

But I think supporting it through -q is enough.

In projects using unittest-style classes you have to use -qq (with -q you still see the xml-like output)

oh, and if it doesn't ,thats a bug

@RonnyPfannschmidt, no it doesn't work with pytest "test.py::TestClass::test_method.

ok, so we have a bug for interaction between collectonly and unittest classes

@thisch can you please open a new issue with that, including a quick example? (I would but I'm short on time right now)

Sure, in a few hours.

@RonnyPfannschmidt Thank you!

In projects using unittest-style classes you have to use -qq (with -q you still see the xml-like output)

Also fixed as of pytest 3.9.1 (probably earlier :stuck_out_tongue_winking_eye:), so I'm closing this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomalkalak picture tomalkalak  路  3Comments

jacquerie picture jacquerie  路  3Comments

krassowski picture krassowski  路  3Comments

RonnyPfannschmidt picture RonnyPfannschmidt  路  3Comments

Balky79 picture Balky79  路  3Comments