45

I'm new to testing with Pytest, and I've run into a minor but annoying hangup.

In the command line test session results, I see my tests passing, but the percentage shown is not 100%, for some tests.

With some aggressive logging, I was able to confirm that my tests are passing as expected.

My question is: what's the meaning of the percentage that is displayed for the collected tests?

Example:

platform win32 -- Python 3.7.0a4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: C:\api-check, inifile:
collected 5 items

test_Me.py ...                                                           [ 60%]
test_env.py ..                                                           [100%]

========================== 5 passed in 6.04 seconds ===========================
ivanleoncz
  • 9,070
  • 7
  • 57
  • 49
klreeher
  • 1,391
  • 2
  • 15
  • 27
  • Percentage of total tesks collected. e.g. collected 5 item... `test_Me.py` has 3 tests = 60%... not super sophisticated – abigperson Apr 09 '18 at 17:05
  • 2
    @abigperson That doesn't make a whole lot of sense. How can 60% of the tests be in `test_Me` and 100% of the tests in `test_env`? Last time I checked, that wasn't how percentages work. – Aran-Fey Apr 09 '18 at 17:07
  • 1
    Perhaps the percentage is cumulative? Try adding a third test file and see what the output looks like. – Code-Apprentice Apr 09 '18 at 17:10
  • 1
    I started a PR to update the pytest docu with the answers provided below (Thanks!): https://github.com/pytest-dev/pytest/pull/6686. Please feel free to comment or vote on it. – Katrin Leinweber Feb 28 '20 at 12:30

2 Answers2

60

This is a makeshift progress bar.

It displays the "percentage of work" done so far -- most probably, total completed tests by the total number of tests to run (that it precalculated at the start).

If your tests ran for longer, you would probably see the number in the line changing as it crunches through the specific file.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
16

It's one of the features included on Pytest, since version 3.3 (2017).

As my comrade @ivan_pozdeev mentioned, it's a progress indicator, indeed.

Here's an example, where you have 4 tests collected:

$ pytest test.py -v
================================ test session starts =============================
platform linux -- Python 3.6.7, pytest-4.4.0, py-1.8.0, pluggy-0.9.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/ivanleoncz/git/pysd
collected 4 items                                                                           
test.py::test_active_services PASSED                                        [ 25%]
test.py::test_enabled_services PASSED                                       [ 50%]
test.py::test_is_enabled PASSED                                             [ 75%]
test.py::test_is_active PASSED                                              [100%]

============================== 4 passed in 0.55 seconds ==========================
  • 100% of the tests / the amount of collected tests == a progression of 25%, from one test to another
ivanleoncz
  • 9,070
  • 7
  • 57
  • 49