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

Fix imports of fixture-decorated function_parameters function in tests with Ruff #118

Open
mcw92 opened this issue Apr 24, 2024 · 0 comments
Assignees
Labels
maintenance Improve code readability and robustness.

Comments

@mcw92
Copy link
Member

mcw92 commented Apr 24, 2024

The fixture-decorated function function_parameters is used in multiple tests for requesting different combinations of benchmark function name and the corresponding global optimum:

@pytest.fixture(
    params=[
        ("rosenbrock", 0.0),
        ("step", -25.0),
        ("quartic", 0.0),
        ("rastrigin", 0.0),
        ("griewank", 0.0),
        ("schwefel", 0.0),
        ("bisphere", 0.0),
        ("birastrigin", 0.0),
        ("bukin", 0.0),
        ("eggcrate", -1.0),
        ("himmelblau", 0.0),
        ("keane", 0.6736675),
        ("leon", 0.0),
        ("sphere", 0.0),  # (fname, expected)
    ]
)
def function_parameters(request):
    """Define benchmark function parameter sets as used in tests."""
    return request.param

When moving the definition of this function to a separate utility module file and importing from this file into the actual tests, ruff falsely recognizes this as an unused import and thus will remove the line:

ruff check test_cmaes.py 
test_cmaes.py:8:25: F401 [*] `tests.utils.function_parameters` imported but unused
test_cmaes.py:11:16: F811 Redefinition of unused `function_parameters` from line 8

This should not be the case and fixed to avoid duplicate code by repeating the definition of function_parameters in each separate test file to be executed.

@mcw92 mcw92 added the maintenance Improve code readability and robustness. label Apr 24, 2024
@mcw92 mcw92 self-assigned this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Improve code readability and robustness.
Projects
None yet
Development

No branches or pull requests

1 participant