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

request.node.get_closest_marker('name') returns None for markers applied in modules #11701

Closed
4 tasks done
8TRobi8 opened this issue Dec 14, 2023 · 2 comments
Closed
4 tasks done
Labels
topic: marks related to marks, either the general marks or builtin

Comments

@8TRobi8
Copy link

8TRobi8 commented Dec 14, 2023

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Description

As mentioned in the title, I cannot send marker value to fixtures with 'module' scope.
I've found something similar, where the 'class' scope was fixed: #902

Minimal example

@pytest.fixture(scope="module")
def foo(request):
   marker = request.node.get_closest_marker("fixt_data")
   if marker is None:
      data = None
   else:
      data = marker.args[0]
   return data

@pytest.mark.fixt_data("C1")
def test_fixt(foo):
    assert fixt == C1

Pip list

Package Version


certifi 2023.11.17
charset-normalizer 3.3.2
docker 7.0.0
exceptiongroup 1.2.0
idna 3.6
iniconfig 2.0.0
Jinja2 3.1.2
junit2html 30.1.3
MarkupSafe 2.1.3
packaging 23.2
paho-mqtt 1.6.1
pip 22.3.1
pluggy 1.3.0
pytest 7.4.3
pytest-docker-fixtures 1.3.18
pytest-html 4.1.1
pytest-metadata 3.0.0
pytest-mqtt 0.3.1
requests 2.31.0
setuptools 65.6.3
tomli 2.0.1
urllib3 2.1.0

Versions

pytest - 7.4.3
MacOS - Sonoma 14.1.2

@The-Compiler
Copy link
Member

Your example has various undefined variables (fixt and C1) - if you post a reproducer, it's always a good idea to actually run it to see if it reproduces the issue 😉

Here is a fixed minimal example:

import pytest

@pytest.fixture(scope="module")
def foo(request):
   marker = request.node.get_closest_marker("fixt_data")
   if marker is None:
      data = None
   else:
      data = marker.args[0]
   return data

@pytest.mark.fixt_data("C1")
def test_fixt(foo):
    assert foo == "C1"

which fails with:

E       AssertionError: assert None == 'C1'

@RonnyPfannschmidt
Copy link
Member

I believe the failure is correct , module scope shouldn't see item scoped marks, if the module attribute was used, it sould work

@Zac-HD Zac-HD added the topic: marks related to marks, either the general marks or builtin label Feb 17, 2024
@Zac-HD Zac-HD closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: marks related to marks, either the general marks or builtin
Projects
None yet
Development

No branches or pull requests

4 participants