Grep: use actual (temp) files instead of mocking out open()

Continuing from Testing file input/output syntax - #11 by BethanyG

I have a commit which I think does everything that is needed. Regardless of how/what/where pytest is executed, that process should be able to create a temp dir and write to it. Any chdir executed inside pytest would not impact the runner’s environment. Unless the test infrastructure relies on pytest somehow writing output and relies on the value of the CWD being predictable after the test setUp() and before tearDown(), both the runner and pytest should not see any changes to the CWD. The pytest will, for the duration of the unit test, change directories, populate files and run the grep() function. After the grep() function returns, the pytest working directory will revert and the tempdir will be cleaned up. The directory changes should not impact the test runner.

Thanks for doing this!

I ran the example.py file against your new test file on Mac and inside the test-runner docker container. It looks good so far. :smile:

I am fading fast tho, so will need to do the failure scenarios, the pathlib stuff, and Windows testing after I get some sleep. Unless you have a Windows system you can test against? Just a little nervous about all those warnings about windows OS in the tempfile module…

I also want to make sure there isn’t any weirdness coughed up when tests fail. There shouldn’t be…but I am a “show me” sorta gal.

With any luck, we’ll be able to get this merged tomorrow.

1 Like

I’m afraid I don’t have a Windows system I can test on. But there’s no rush on this, either. Thanks!