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

Current test decoraters or base test class pollute project directory #148

Open
cmutel opened this issue Aug 23, 2023 · 2 comments
Open

Current test decoraters or base test class pollute project directory #148

cmutel opened this issue Aug 23, 2023 · 2 comments
Assignees

Comments

@cmutel
Copy link
Member

cmutel commented Aug 23, 2023

All classes should create projects in temporary directories, but this isn't happening for some reason.

@cmutel cmutel self-assigned this Aug 23, 2023
@jsvgoncalves
Copy link
Member

jsvgoncalves commented Jun 14, 2024

Came here to create this exactly issue, the issue is contained here:

# bw2data/project.py
projects = ProjectManager()
# bw2data/tests.py

from .project import projects

@wrapt.decorator
def bw2test(wrapped, instance, args, kwargs):
    # …
    projects.change_base_directories(
        base_dir=tempdir, base_logs_dir=tempdir, project_name=project_name, update=False
    )
    projects._is_temp_dir = True
    # …

Since projects is a singleton, changing its state in the wrapper changes it for everyone. As a rule of thumb, always restore mocked or patched objects.

Probably the best way going forward is to refactor testing and use pytest's fixtures.

@jsvgoncalves
Copy link
Member

Maybe this isn't the issue you tried to describe, but at least related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants