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

regression: testdir fixture not found with pytester plugin loaded #9280

Closed
The-Compiler opened this issue Nov 8, 2021 · 5 comments · Fixed by #9286
Closed

regression: testdir fixture not found with pytester plugin loaded #9280

The-Compiler opened this issue Nov 8, 2021 · 5 comments · Fixed by #9286
Labels
plugin: pytester related to the pytester builtin plugin type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously
Milestone

Comments

@The-Compiler
Copy link
Member

After #9208, this:

pytest_plugins = 'pytester'

def test_testdir(testdir):
    pass

fails with:

============================= test session starts ==============================
platform linux -- Python 3.9.7, pytest-7.0.0.dev294+g86446edc8, pluggy-1.0.0
rootdir: /home/florian/tmp/td
collected 1 item                                                               

test_td.py E                                                             [100%]

==================================== ERRORS ====================================
________________________ ERROR at setup of test_testdir ________________________
file /home/florian/tmp/td/test_td.py, line 3
  def test_testdir(testdir):
E       fixture 'testdir' not found
>       available fixtures: LineMatcher, _config_for_test, _pytest, _sys_snapshot, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, linecomp, monkeypatch, pytestconfig, pytester, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/home/florian/tmp/td/test_td.py:3
=========================== short test summary info ============================
ERROR test_td.py::test_testdir
=============================== 1 error in 0.01s ===============================

I bisected this to e6eac28.

Considering this as a showstopper for 7.0 given that this is a very common way of accessing the testdir fixture.

cc @bluetech

@The-Compiler The-Compiler added plugin: pytester related to the pytester builtin plugin type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously labels Nov 8, 2021
@The-Compiler The-Compiler added this to the 7.0 milestone Nov 8, 2021
@bluetech
Copy link
Member

bluetech commented Nov 8, 2021

Right, has_plugin("pytester") is not going to work at configure time when its loaded from a conftest, didn't think of that.

I'll send a PR to revert this commit, see this discussion on why I added it. Maybe @RonnyPfannschmidt has an idea how to salvage it though. Anyway it's not too bad without it.

bluetech added a commit to bluetech/pytest that referenced this issue Nov 8, 2021
…sponding plugins are registered"

This reverts commit e6eac28.

This approach doesn't work when pytester is loaded thru a conftest
`pytest_plugins`.

Fixes pytest-dev#9280.
@RonnyPfannschmidt
Copy link
Member

Let's register pytester legacy in the pytest plugin registred hook so we auto enable when pytester gets activated

We need a condition on the plugin

@bluetech
Copy link
Member

bluetech commented Nov 8, 2021

The idea is to eventually move the plugin to be standalone, so I prefer the approach to be compatible with that. Can you think of a trick that would keep it localized to the legacypath plugin? Hmm maybe use pytest_plugin_registered (in addition to configure)?

@RonnyPfannschmidt
Copy link
Member

Exactly that 😅

@bluetech
Copy link
Member

bluetech commented Nov 8, 2021

I should learn to read :) (I read it as loading the sub-plugin from the pytester plugin)

bluetech added a commit to bluetech/pytest that referenced this issue Nov 8, 2021
Fixes pytest-dev#9280.

Previous approach didn't support pytester being loaded using
`pytest_plugins = "pytester"` in a conftest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: pytester related to the pytester builtin plugin type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
3 participants