Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show deselected info after collected info and before test execution #1527

Closed
fontealpina opened this issue Apr 20, 2016 · 12 comments
Closed
Labels
topic: collection related to the collection phase type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@fontealpina
Copy link

In my workflow, may be useful get the informations about deselected tests after the collected info an before the beginning of tests executed, because (especially if the test execution takes a long time), I would check if I have properly selected the test to run.
For instance, would be nice something like this:

$pytest -v -s test_try.py -m fast
============================ test session starts ============================
platform linux2 -- Python 2.7.6 -- py-1.4.26 -- pytest-2.9.1 -- /usr/bin/python
collected 4 items 
===================== 3 tests deselected by "-m 'fast'" =====================
test_try.py .

Currently this info is shown after the test execution.
I was wondering if there is an easy way to get this also before the test execution, maybe writing a plugin?

Thanks

@nicoddemus
Copy link
Member

nicoddemus commented Apr 20, 2016

A plugin is possible I guess, but I wonder if it makes sense to change this behavior in pytest itself:

$pytest -v -s test_try.py -m fast
============================ test session starts ============================
platform linux2 -- Python 2.7.6 -- py-1.4.26 -- pytest-2.9.1 -- /usr/bin/python
collected 4 items (3 deselected by "-m 'fast'")
test_try.py .

@nicoddemus nicoddemus added the topic: collection related to the collection phase label Apr 20, 2016
@RonnyPfannschmidt
Copy link
Member

sounds like a good idea

@fontealpina
Copy link
Author

ok, for me this would be super.
Maybe wouldn't be better print the number of 'selected' tests instead of the 'deselected' ones?

@RonnyPfannschmidt
Copy link
Member

if we just print the number of selected ones we also avoid the bug wrt deselection reasons

@nicoddemus
Copy link
Member

@RonnyPfannschmidt hmm which bug do you mean?

@RonnyPfannschmidt
Copy link
Member

#1372

@nicoddemus
Copy link
Member

I see, thanks!

@arunksaha
Copy link

arunksaha commented Jan 8, 2018

+1. A list of deselected tests would be useful.

For example, when I see

==================================================================================== 11 tests deselected ====================================================================================
========================================================================= 45 passed, 11 deselected in 35.98 seconds =========================================================================

it will be useful for me to be able to quickly find out which 11 tests were deselected.

@The-Compiler
Copy link
Member

I don't think it's a good idea to print such a list by default. If I use -m foo or -k foo, I don't want a list of hundreds/thousands of tests I'm explicitly not interested in.

@arunksaha
Copy link

@The-Compiler Agree, listing hundreds/thousands of tests by default won't be a good idea :)

How about listing them when an additional flag, such as --list-deselected, is specified?

@nicoddemus
Copy link
Member

I agree with @The-Compiler, if this functionality is implemented it should definitely be opt-in. 😁

@nicoddemus nicoddemus added type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature labels Jan 9, 2018
@twmr
Copy link
Contributor

twmr commented Feb 12, 2018

The following patch adds the deselection count to the 'collected' line, but does not yet remove the deselection summary (==== X tests deselected ====).

WDYT should we remove this summary line if the deselection count is part of the 'collected' line?

diff --git a/_pytest/terminal.py b/_pytest/terminal.py
index 51d21cb..e5c5d9d 100644
--- a/_pytest/terminal.py
+++ b/_pytest/terminal.py
@@ -356,6 +356,8 @@ class TerminalReporter(object):
 
         errors = len(self.stats.get('error', []))
         skipped = len(self.stats.get('skipped', []))
+        deselected = len(self.stats.get('deselected', []))
+
         if final:
             line = "collected "
         else:
@@ -365,6 +367,8 @@ class TerminalReporter(object):
             line += " / %d errors" % errors
         if skipped:
             line += " / %d skipped" % skipped
+        if deselected:
+            line += " / %d deselected" % deselected
         if self.isatty:
             self.rewrite(line, bold=True, erase=True)
             if final:
@@ -372,6 +376,7 @@ class TerminalReporter(object):
         else:
             self.write_line(line)
 
+    @pytest.hookimpl(trylast=True)
     def pytest_collection_modifyitems(self):
         self.report_collect(True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

6 participants