pytest-deadfixtures icon indicating copy to clipboard operation
pytest-deadfixtures copied to clipboard

Tests are not executed when using --dead-fixtures

Open sobolevn opened this issue 6 years ago • 5 comments

As I have already mentioned in https://github.com/jllorencetti/pytest-deadfixtures/issues/16#issuecomment-385154686 this plugin breaks the test count in the output.

How it is now

It seams that this plugin breaks something related with the tests count. As we can clearly see that 16 tests were collected, but no tests ran.

============================= test session starts ==============================
platform linux -- Python 3.6.5, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /home/travis/build/wemake-services/wemake-django-template, inifile: setup.cfg
plugins: isort-0.1.0, flake8-1.0.0, deadfixtures-2.0.1, cookies-0.3.0
collected 16 items                                                             
Cool, every declared fixture is being used.

========================= no tests ran in 0.02 seconds =========================
The command "pipenv run python -m pytest" exited with 0.

Link to the build: https://travis-ci.org/wemake-services/wemake-django-template/builds/372351651

How it should be

============================= test session starts ==============================
platform linux -- Python 3.6.5, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /home/travis/build/wemake-services/wemake-django-template, inifile: setup.cfg
plugins: isort-0.1.0, flake8-1.0.0, deadfixtures-2.0.0, cookies-0.3.0
collected 16 items                                                             
Cool, every declared fixture is being used.

....
========================= 4 tests ran in 0.02 seconds =========================
The command "pipenv run python -m pytest" exited with 0.

Env

Here're my exact versions:

  • python: 3.6.5,
  • pytest: ==3.5.1
  • pytest-deadfixtures: ==2.0.1

sobolevn avatar Apr 28 '18 14:04 sobolevn

Oh, now I see, I thought you were expecting 51 items to be collected. Not running the tests is expected for --dead-fixtures, "by design". I'll update the docs to make it clear, at least for now. What you could do is add it as an extra step in your build process, like this.

jllorencetti avatar Apr 28 '18 15:04 jllorencetti

@jllorencetti oh, that's a surprise for me.

Could you please explain this design decision? Current behavior makes the process a lot less pleasant.

sobolevn avatar Apr 28 '18 18:04 sobolevn

@sobolevn when I first created the plugin I wasn't expecting it to be used for other people so I made it fit my particular workflow. Makes sense to leave this issue open, but I won't be able to take a look at it right now, so I'll at a note about this behavior in the docs.

jllorencetti avatar Apr 28 '18 18:04 jllorencetti

So, can I make this change?

I see it to be like this:

  1. When running with --dead-fixtures tests are collected and executed as usual
  2. If some dead fixtures are found, tests fail with exit code 1
  3. When running with --dup-fixtures tests are collected and executed as usual
  4. If some duplicate fixtures are found, tests fail with exit code 1

I guess 2 and 4 should be executed as soon as possible, so we don't have to waste users time on actually running any tests.

@jllorencetti what do you think?

sobolevn avatar Apr 28 '18 18:04 sobolevn

@sobolevn looks good to me. Thanks! :)

jllorencetti avatar Apr 28 '18 18:04 jllorencetti