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

Factor out the run-in-a-temporar-directory pytest fixture into conftest.py #426

Open
mwcraig opened this issue Aug 14, 2024 · 0 comments
Open
Labels
tests Issue related to tests
Milestone

Comments

@mwcraig
Copy link
Contributor

mwcraig commented Aug 14, 2024

Right now there are several places (and one more on the way) where we repeat this block of code:

    # This auto-used fixture changes the working directory to the temporary directory
    # and then changes back to the original directory after the test is done.
    @pytest.fixture(autouse=True)
    def change_to_tmp_dir(self, tmp_path):
        original_dir = os.getcwd()
        os.chdir(tmp_path)
        # Yielding here is important. It means that when the test is done, the remainder
        # of the function will be executed. This is important because the test is run in
        # a temporary directory and we want to change back to the original directory
        # when the test is done.
        yield
        os.chdir(original_dir)

We should move this to conftest.py (but will need to take out the autouse=True maybe). In places we are currently using it with autouse=True we will to keep a small fixture in place to specify the autouse=True part.

If we take out the autouse thing in conftest then using the fixture would look like this (I think this is untested):

@pytest.fixture(autouse=true)
def run_in_temp_dir(self, change_to_tmp_dir):
    pass
@mwcraig mwcraig added the tests Issue related to tests label Aug 14, 2024
@mwcraig mwcraig added this to the 2.1.0 milestone Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Issue related to tests
Projects
None yet
Development

No branches or pull requests

1 participant