Opened at 2015-05-26T15:17:27Z
Last modified at 2021-03-30T18:40:19Z
#2432 new defect
consistently use self.mktemp() to create a temporary directory in tests
Reported by: | daira | Owned by: | daira |
---|---|---|---|
Priority: | normal | Milestone: | soon |
Component: | code | Version: | 1.10.0 |
Keywords: | tests cleanup | Cc: | |
Launchpad Bug: |
Description
Currently we use a hotchpotch of methods to create a temporary directory for a test -- specifying the name manually, using a workdir method, using self.mktemp() from twisted.trial.unittest.TestCase, etc. (It is usually consistent within a test module but not across modules.)
We should just use self.mktemp(), or if there is something wrong with that then we should consistently use our own mixin.
Change History (9)
comment:1 follow-up: ↓ 2 Changed at 2015-05-26T16:01:59Z by warner
comment:2 in reply to: ↑ 1 Changed at 2015-05-26T18:02:17Z by daira
Replying to warner:
So I guess I'm in favor of using our own mixin that uses the (fully-qualified) name of the test case to produce a subdirectory of _trial_temp.
mktemp() from twisted.trial.unittest.TestCase already does that.
comment:3 Changed at 2015-05-26T18:15:13Z by daira
The one thing I don't like about mktemp() is that the path it generates is not deterministic, due to its use of mkdtemp (implementation in Twisted v15.2.0). What I actually want is os.path.dirname(os.path.dirname(self.mktemp()), I think. So, maybe it would be better to have a mixin to shorten that, and so that if we want to change it, we can do so in only one place.
comment:4 Changed at 2015-05-26T18:18:02Z by daira
Also, I think I'd prefer for our mixin method to return an absolute Unicode path, rather than a relative str path.
comment:5 Changed at 2016-03-22T05:02:52Z by warner
- Milestone changed from 1.11.0 to 1.12.0
Milestone renamed
comment:6 Changed at 2016-06-28T18:20:37Z by warner
- Milestone changed from 1.12.0 to 1.13.0
moving most tickets from 1.12 to 1.13 so we can release 1.12 with magic-folders
comment:7 Changed at 2020-01-17T16:15:13Z by exarkun
Probably switch to testtools and use the TempDir? fixture.
comment:8 Changed at 2020-06-30T14:45:13Z by exarkun
- Milestone changed from 1.13.0 to 1.15.0
Moving open issues out of closed milestones.
comment:9 Changed at 2021-03-30T18:40:19Z by meejah
- Milestone changed from 1.15.0 to soon
Ticket retargeted after milestone closed
I agree it's a bit of a mess. My only two concerns:
Trial puts everything in ./_trial_temp, and rmtrees it at the beginning of each test run. This provides a predictable location, and an upper bound (of size=1) on the litter.
So I guess I'm in favor of using our own mixin that uses the (fully-qualified) name of the test case to produce a subdirectory of _trial_temp.