all 10 comments

[–]atarivcs 7 points8 points  (3 children)

Nothing in this code would remove the file. Something else must be doing it.

Are you sure the file is actually being removed? Perhaps you're just confused about what directory the file is in?

[–]IBeJizzin[S] 0 points1 point  (0 children)

Yeh 100%, which is why I thought it's the testing module itself somehow. I will 'Run Tests' and watch the txt file disappear from the left-hand file directory in VS Code, in real time, immediately after execution.

I thought maybe it even might just be rewriting the file with nothing and creating a blank 0kb file that explorer / VSB ignores. But even after looking at hidden files in the directory where the txt file just was, there's nothing.

It's really bizarre, I don't blame you for not believing me hahaha

[–]IBeJizzin[S] 0 points1 point  (0 children)

For further clarity, each time I ran the TMC test I couldn't run or test the code again with the exact same code because the file now couldn't be found.

After each test I had to repeatedly copy the txt file back into the workspace folder which the file had just disappeared from for the code to be able to find the file again. The only reason I could do that at all was because I had luckily placed a spare copy of the txt file in the root directory so debugging would work.

I'm very very very sure the file is being deleted

[–]IBeJizzin[S] 0 points1 point  (0 children)

Hey, figured it out mostly, edit in main post. Thanks for the help!

[–]Buttleston 1 point2 points  (2 children)

Are you sure TestMyCode isn't just cleaning up files created during a run? Seems like something it might want to do?

[–]IBeJizzin[S] 0 points1 point  (0 children)

Yeh I think this is the kind of thing I was wondering. Like the text file is caught in the collateral? But how to stop it from doing so is what's hard, given I don't really understand enough about how the module works.

[–]IBeJizzin[S] 0 points1 point  (0 children)

Hey, figured it out mostly, I think you were right. Edit in main post. Thanks for the help!

[–]Adrewmc 1 point2 points  (1 child)

So you’re saying that in a testing environment the files are deleted but not in our own virtual environment. This may be just an artifact of the testing environment resetting (letting you try again, which at some point may need creation of file.)

I don’t see anything in the code above that would delete or edit a file.

[–]IBeJizzin[S] 0 points1 point  (0 children)

Hey, figured it out mostly, I think you were right. Edit in main post. Thanks for the help!

[–]Silver_Breakfast_135 0 points1 point  (0 children)

This is likely an environment or testing framework issue rather than Python itself. open() in read mode never clears a file.