Problems using nose in a virtualenv

后端 未结 8 1969
-上瘾入骨i
-上瘾入骨i 2020-12-24 04:57

I am unable to use nose (nosetests) in a virtualenv project - it can\'t seem to find the packages installed in the virtualenv environment.

The odd thing is that i ca

相关标签:
8条回答
  • 2020-12-24 05:35

    I got a similar problem. The following workaround helped:

    python `which nosetests` 
    

    (instead of just nosestests)

    0 讨论(0)
  • 2020-12-24 05:40

    You might have a nosetests that is installed somewhere else in your PATH with higher priority than the one installed in your virtualenv. A quick way to give the nose module and associated nosetests script installed in your current virtualenv top priority is to edit your PATH:

    export PATH=/path/to/current/virtualenv/bin:$PATH
    
    0 讨论(0)
  • 2020-12-24 05:41

    If all else fails, try installing nose in your venv, and/or run nosetests-2.7. I believe @andrea-zonca's answer has the same effect if your venv python is 2.7

    0 讨论(0)
  • 2020-12-24 05:45

    You need to have a copy of nose installed in the virtual environment. In order to force installation of nose into the virtualenv, even though it is already installed in the global site-packages, run pip install with the -I flag:

    (env1)$ pip install nose -I
    

    From then on you can just run nosetests as usual.

    0 讨论(0)
  • 2020-12-24 05:47

    Are you able to run myenv/bin/python /usr/bin/nosetests? That should run Nose using the virtual environment's library set.

    0 讨论(0)
  • 2020-12-24 05:47

    Here's what works for me:

    $ virtualenv --no-site-packages env1
    $ cd env1
    $ source bin/activate            # makes "env1" environment active,
                                     # you will notice that the command prompt
                                     # now has the environment name in it.
    
    (env1)$ easy_install nose        # install nose package into "env1"
    

    I created a really basic package slither that had, in its setup.py, same test_suite attribute as you mentioned above. Then I placed the package source under env1/src.

    If you looked inside env1/src, you'd see:

    slither/setup.py
    slither/slither/__init__.py
    slither/slither/impl.py          # has some very silly code to be tested
    slither/slither/tests.py         # has test-cases 
    

    I can run the tests using test subcommand:

    (env1)$ pushd src/slither
    (env1)$ python setup.py test
    # ... output elided ...
    test_ctor (slither.tests.SnakeTests) ... ok
    test_division_by_zero (slither.tests.SnakeTests) ... ok
    Ran 2 tests in 0.009s
    OK
    (env1)$ popd
    

    Or, I can run the same tests with nosetests:

    (env1)$ pushd src
    (env1)$ nosetests slither/
    ..
    Ran 2 tests in 0.007s
    OK
    (env1)$ popd
    

    Also note that nosetests can be picky about executables. You can pass --exe if you want it to discover tests in python modules that are executable.

    0 讨论(0)
提交回复
热议问题