[Twisted-Python] Twisted Trial changes working directory
![](https://secure.gravatar.com/avatar/d4931f32b2fb69d4d6067106e0f83535.jpg?s=120&d=mm&r=g)
I have a (Twisted) program that saves & uses a file in the current working directory. When running tests for the program, Trial changes the working directory, causing this file to be written into the '_trial_temp' directory instead. ...so the program works differently when run via Trial vs. in normal use. There are a number of solutions to this, but I'd just like to understand the reasoning behind this surprising behaviour. The docs say that this: "...allows them to write whatever data they like to disk, and not worry about polluting the current working directory" ...couldn't they just do this without changing the working directory? One of the things I love about python is that things just seem to work like you expect - I'm rarely surprised by it's behaviour. Twisted, OTOH, continually surprises me...and not like getting-a-pony-on-your-10th-birthday type of surprise. Don't get me wrong, I love Twisted...it makes writing networked/asynchronous programs a breeze. ...everything I write now (in Python), just seems to "need" Twisted. I just find Twisted's idiosyncrasies frustrating sometimes. Sorry for the rant, Gerrat
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Fri, 3 Jul 2009 10:17:12 -0400, Gerrat Rickert <grickert@coldstorage.com> wrote:
I have a (Twisted) program that saves & uses a file in the current working directory. When running tests for the program, Trial changes the working directory, causing this file to be written into the '_trial_temp' directory instead. ...so the program works differently when run via Trial vs. in normal use.
The only difference I can infer from your description is whether the file in question is created in the directory you invoke the program from (in the non-trial case) or in the _trial_temp subdirectory of that directory (in the trial case). It's not obvious to me why this might be a problem.
There are a number of solutions to this, but I'd just like to understand the reasoning behind this surprising behaviour. The docs say that this: "...allows them to write whatever data they like to disk, and not worry about polluting the current working directory" ...couldn't they just do this without changing the working directory?
This is an ancient feature of trial, from the days when Twisted's own test suite (the primary driver of trial development for many years) was even more crufty than it is today. In those days, many tests just created files in the working directory. The _trial_temp feature provided a single fix which addressed the mess created by all of the tests in one fell swoop. The behavior is still convenient for tests which aren't written carefully in this regard. Jean-Paul
![](https://secure.gravatar.com/avatar/d4931f32b2fb69d4d6067106e0f83535.jpg?s=120&d=mm&r=g)
-----Original Message----- From: twisted-python-bounces@twistedmatrix.com [mailto:twisted-python- bounces@twistedmatrix.com] On Behalf Of Jean-Paul Calderone Sent: Friday, July 03, 2009 11:27 AM To: Twisted general discussion Subject: Re: [Twisted-Python] Twisted Trial changes working directory
I have a (Twisted) program that saves & uses a file in the current working directory. When running tests for the program, Trial changes the working
On Fri, 3 Jul 2009 10:17:12 -0400, Gerrat Rickert <grickert@coldstorage.com> wrote: directory,
causing this file to be written into the '_trial_temp' directory instead. ...so the program works differently when run via Trial vs. in normal use.
The only difference I can infer from your description is whether the file in question is created in the directory you invoke the program from (in the non-trial case) or in the _trial_temp subdirectory of that directory (in the trial case). It's not obvious to me why this might be a problem.
...and it turns out not to really be a Trial-specific problem - more a problem with my expectations. The file takes a while to generate, and I just expected it to be there after running the program the first time. - it will get regenerated if it doesn't exist, and I can easily copy it to the _trial_temp directory for testing
There are a number of solutions to this, but I'd just like to
the reasoning behind this surprising behaviour. The docs say that this: "...allows them to write whatever data they
understand like
to disk, and not worry about polluting the current working directory" ...couldn't they just do this without changing the working directory?
This is an ancient feature of trial, from the days when Twisted's own test suite (the primary driver of trial development for many years) was even more crufty than it is today. In those days, many tests just created files in the working directory. The _trial_temp feature provided a single
fix
which addressed the mess created by all of the tests in one fell swoop. The behavior is still convenient for tests which aren't written carefully in this regard.
Jean-Paul
Thanks for the explanation.
participants (2)
-
Gerrat Rickert
-
Jean-Paul Calderone