-
Notifications
You must be signed in to change notification settings - Fork 420
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
Isolated temp dir per run #283
Comments
The problem of handling temporary directories is solved, the question is whether it belongs to the core and the convenient answer is no. Which percentage of tests need this functionality? We probably don't know, and a smaller focused library is better than a bigger broader one. So, I rather support #276. |
"solved" is a bit strong given that this requires a separate library that hasn't even been pulled into the bats-core org yet. It's reasonable to decide that file-system dependent assertions and test utilities should live in a separate library, but bats-core is responsible for test setup and teardown, and for the environment made available to tests. The existing documented behavior is error-prone, and will remain so even if people are supposed to use bats-file. I'd be happy to see that issue resolved, but it doesn't address this problem. |
So We could debate endlessly. ;-) |
Maybe we're talking past each other - are you suggesting the current behavior of If you don't think any file system hooks should be provided by bats-core that's fair, but in that case |
Maybe add some trap to clean it up after bats terminates, from either a regular return or all other signals. I would not advise users to use that for their tests, just let them run |
Since Having |
Anecdotally, I've needed isolated temporary directories without needing custom file assertions. For example, testing a program that caches data somewhere requires having a isolated "somewhere" to point it at, even if you don't actually need to inspect the resulting contents of the cache. |
Well, you could have asserted that the cache directory is actually used ;-) I can imagine
Not sure how to accomodate for this syntactically, as there are no test attributes (yet). |
I really don't see why the existing behavior that BATS runs everything in the same directory (especially across runs!) would be desirable. Is there some negative consequence of changing this behavior that you're concerned about? Put another way, suppose BATS had always run tests in isolated directories; would you want to see that replaced with the current behavior? |
While I'm not a |
But it doesn't work, that's the motivation for this issue :) Running separate tests in the same directory, and especially sharing that directory across different runs, is a recipe for unexpected behavior. Any state a test changes will persist for the next test or next run, which can introduce flakiness, brittleness, or hard-to-reproduce issues. The test framework should not force this sort of non-hermetic behavior on tests. |
You still silently assume that a test needs a directory to run, just because your tests do. My point is that with the temporary directory isolation alone, tests' behavior will remain non-hermetic. Tools access home directory, |
I agree with your premise, but BATS is already in an inconsistent state; the documentation recommends using Personally, I think it would be better to actually give each test (or at least each |
I agree that |
I would love to see this too. Had to create a wrapper in order to handle the creation (and destruction) of said "test run" folder. I'm not a big fan though since I now longer can invoke This as well as having a global (per test run) setup/teardown would be great additions to managing state. |
There is a partial solution since v1.2.1. See this comment: #226 (comment) |
The README points to
BATS_TMPDIR
as a "location to a directory that may be used to store temporary files", but currently it's (typically) just/tmp
or$TMPDIR
, meaning that anything written to that directory will affect subsequent runs.BATS itself appears to instead use
BATS_TMPNAME
which is keyed off the PID (which still isn't safe, as the OS will reuse PIDs over time), but it's not clear whether users are supposed to useBATS_TMPNAME
or if it's an implementation detail.I would suggest providing a different variable, e.g.
BATS_TEST_TMP
, that is unique per-run, and documenting that in the README instead ofBATS_TMPDIR
. I'd also suggest changingBATS_TMPNAME
to not (only) rely on the PID, but I'm not sure if there are additional constraints with that -BATS_PARENT_TMPNAME
makes me suspicious parts of BATS currently relies on this naming scheme.The text was updated successfully, but these errors were encountered: