.. _redefined-outer-name:

redefined-outer-name / W0621
============================

**Message emitted:**

Redefining name %r from outer scope (line %s)

**Description:**

*Used when a variable's name hides a name defined in an outer scope or except handler.*

**Problematic code:**

.. literalinclude:: /data/messages/r/redefined-outer-name/bad.py
   :language: python

**Correct code:**

.. literalinclude:: /data/messages/r/redefined-outer-name/good.py
   :language: python

**Additional details:**

A common issue is that this message is triggered when using `pytest` `fixtures <https://docs.pytest.org/en/7.1.x/how-to/fixtures.html>`_:

.. code-block:: python

    import pytest

    @pytest.fixture
    def setup():
        ...


    def test_something(setup):  # [redefined-outer-name]
        ...

One solution to this problem is to explicitly name the fixture:

.. code-block:: python

    @pytest.fixture(name="setup")
    def setup_fixture():
        ...

Alternatively `pylint` plugins like `pylint-pytest <https://pypi.org/project/pylint-pytest/>`_ can be used.


Created by the `variables <https://github.com/PyCQA/pylint/blob/main/pylint/checkers/variables.py>`__ checker.