3

I have used conda build to successfully build packages for fftw and pyfftw. I am now trying to write a run_test.py routine to execute the tests in pyfftw as part of the build process. I wrote a run_test.py to run just one of the test files in pyfftw:

import os
path=os.environ.get('SRC_DIR')
execfile(path+'/test/test_pyfftw_real_backward.py')

At the end of the build, I get the following error:

Traceback (most recent call last):
  File "/data/miniconda/conda-bld/test-tmp_dir/run_test.py", line 38, in <module>
    execfile(path+'/test/test_pyfftw_real_backward.py')
  File "/data/miniconda/conda-bld/work/pyFFTW-0.9.2/test/test_pyfftw_real_backward.py", line 24, in <module>
    from .test_pyfftw_base import run_test_suites
ValueError: Attempted relative import in non-package
TESTS FAILED: pyfftw-0.9.2-np18py27_0

Do I add the files to the package? Or maybe copy the files to the test environment? I am actually at a loss on how to proceed. Any help would be appreciated.

user3654344
  • 316
  • 1
  • 5

1 Answers1

0

There are a few things here (this question was asked quite long ago).

The problem above is that you can't do a relative import via from .something import ... - not because the file doesn't exist, but because you're running this as a file, which is analogous to:

python test/my_test.py

It would work if you did something like:

python -m test.my_test

But, execfile is not like that, and besides - it's already in the past: What is an alternative to execfile in Python 3?

Next things, for people who come here accidentally - you shouldn't use SRC_DIR like that, or you'll get:

ValueError: In conda-build 2.1+, the work dir is removed by default before 
the test scripts run.  You are using the SRC_DIR variable in your test script,
but these files have been deleted.  Please see the  documentation regarding
the test/source_files meta.yaml section, or pass the --no-remove-work-dir flag.

The right way to have a For more information about configuring tests for conda packages, see here: https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#test-section

So, you should make your tests self-contained, or at least they should do something like:

import os
import sys

sys.path.append(os.path.dirname(__file__))
import test_common
# etc.

And to have a working setup of test/ subdirectory in sources, just use:

test:
  requires:
   - nose
  source_files:
   - test/*.py
  commands:
   - nosetests

Don't worry about the shortness of this configuration -- less code is less maintenance.

Tomasz Gandor
  • 8,235
  • 2
  • 60
  • 55