Repository: conda/conda-build

Issue:
test:imports doesn't work if conda-root python version doesn't match the package's required python
I'm using the python-2.7 version of Miniconda.  IIUC, I should still be able to use conda-build to generate python-3 packages.  However, I get a failure for this test case:

``` yaml
package:
 name: my-py3-library
 version: 0.1

requirements:
 build:
  - python 3.5*

 run:
  - python 3.5*

test:
 imports:
  - sys
```

```
$ conda build my-py3-library 
Removing old build environment
Removing old work directory
BUILD START: my-py3-library-0.1-py35_0
Fetching package metadata: ........
Solving package specifications: .
The following NEW packages will be INSTALLED:

    openssl:    1.0.1k-1     
    pip:        7.1.2-py35_0 
    python:     3.5.0-0      
    readline:   6.2-2        
    setuptools: 18.1-py35_0  
    sqlite:     3.8.4.1-1    
    tk:         8.5.18-0     
    wheel:      0.24.0-py35_0
    xz:         5.0.5-0      
    zlib:       1.2.8-0      

Linking packages ...
[      COMPLETE      ]|###################################################################################################################################################| 100%
Removing old work directory
Copying /Users/bergs/Documents/workspace/ilastik-build-conda/my-py3-library to /miniconda/conda-bld/work
Package: my-py3-library-0.1-py35_0
source tree in: /miniconda/conda-bld/work
number of files: 0
Fixing permissions
Fixing permissions
BUILD END: my-py3-library-0.1-py35_0
TEST START: my-py3-library-0.1-py35_0
Fetching package metadata: ........
Solving package specifications: ..
Error: Unsatisfiable package specifications.
Generating hint: 
[      COMPLETE      ]|###################################################################################################################################################| 100%

Hint: the following packages conflict with each other:
  - my-py3-library 0.1 py35_0
  - python 2.7*

Use 'conda info my-py3-library' etc. to see the dependencies for each package.
```

The `python 2.7*` spec requirement comes from [this line](https://github.com/conda/conda-build/blob/274cd1218722bab72acfa462edaf96427b554f04/conda_build/build.py#L537).

That function expects the python spec to be included in the tests section explicitly, even though it was already included in the `requirements:build` section.

The test case above can be fixed by extending the `test:` section:

``` yaml
test:
 imports:
  - sys

 requires:
  - python 3.5*
```

...but IIUC, `conda-build` shouldn't need that redundant spec.

A proposed fix for this can be found in ~~PR #588~~ PR #590.



Discussion:

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -526,15 +526,12 @@ def test(m, verbose=True, channel_urls=(), override_channels=False):
     specs = ['%s %s %s' % (m.name(), m.version(), m.build_id())]
 
     # add packages listed in test/requires
-    specs_include_python = False
-    for spec in m.get_value('test/requires', []):
-        specs.append(spec)
-        if spec.startswith('python ') or spec == 'python':
-            specs_include_python = True
-
-    if py_files and not specs_include_python:
-        # as the tests are run by python, we need to specify it
-        specs += ['python %s*' % environ.get_py_ver()]
+    specs += m.get_value('test/requires', [])
+
+    if py_files:
+        # as the tests are run by python, ensure that python is installed.
+        # (If they already provided python as a run or test requirement, this won't hurt anything.)
+        specs += ['python']
     if pl_files:
         # as the tests are run by perl, we need to specify it
         specs += ['perl %s*' % environ.get_perl_ver()]


Test patch: