views:

165

answers:

3

I have a Python project building with Hudson. Most unit tests work correctly, but any tests that require writing to the file system (I have a class that uses tarfiles, for example) can't find the tmp directory I have set up for intermediate processing (my tearDown methods remove any files under the relative tmp directory).

Here is my project structure:

  • src
    • tests
      • fixtures (static files here)
      • unit (unit tests here)
    • tmp

Here is an example error:

OSError: [Errno 2] No such file or directory: '../../tmp'

I assume this is happening because Hudson is not processing the files while in the directory unit, but rather some other working directory.

What is Hudson's working directory? Can it be configured? Can relative paths work at all?

A: 

I don't know anyhting about Hudson, but this is what I do to ensure, that relative path are working right:

os.chdir(os.path.dirname(sys.argv[0]))
kepkin
+2  A: 

Each job in Hudson has it's own working directory, at /path/to/hudson/jobs/[job name]/workspace/

For individual jobs, you can set the "Use custom workspace" option (under "Advanced Project Options") to define where the workspace will be.

I guess it would depend on how your tests are being run, but if you inspect the job's workspace you should be able to find where Hudson is writing the files to.

rjohnston
+1  A: 

I don't know how you're initializing your workspace, but typically it's done by checking your project out of version control into the workspace. If this is true in your case, the easiest thing to do is to add your tmp directory to version control (say, with a README file in it, if your version control system doesn't support directories). Then, the tmp directory will get checked out into your workspace and things should work again.

Vinay Sajip
I added the tmp dir manually because my unit tests clear it out every tearDown. I also made sure to call nosetests with the -w flag: nosetests -w tests/unit --with-xunit
Wraith
If it is really a temporary directory that is only used by the test it should be created by the setUp and removed by the tearDown of that same test. I always refuse to add temp or result directories to the SCM.
cringe
@cringe - Good advice; I revised my unit tests to use a proper tmp dir instead of one associated with any sourcecode.
Wraith