def test_function_with_square_brackets(self, pytester: Pytester) -> None:
        """Check that functions with square brackets don't cause trouble."""
        p1 = pytester.makepyfile(
            """
            locals()["test_foo[name]"] = lambda: None
            """
        )
        result = pytester.runpytest("-v", str(p1))
        result.stdout.fnmatch_lines(
            [
                "test_function_with_square_brackets.py::test_foo[[]name[]] PASSED *",
                "*= 1 passed in *",
            ]
        )
Check that functions with square brackets don't cause trouble.
testing/python/collect.py