[TIP] Testing Flask apps in a pyvenv environment
Randy Syring
randy at thesyrings.us
Wed Jul 8 22:08:23 PDT 2015
>
> Is there a reason py.test can't find the flask module in the pyvenv
> created virtual environment?
Are you sure you are using py.test from your virtualenv and not from the
system? Run `py.test --version` to help with this:
> (foo)rsyring at loftex:~$ py.test --version
> This is pytest version 2.7.1, imported from
> /home/rsyring/.virtualenvs/foo/local/lib/python2.7/site-packages/pytest.pyc
> setuptools registered plugins:
> pytest-cov-1.8.1 at
> /home/rsyring/.virtualenvs/foo/local/lib/python2.7/site-packages/pytest_cov.pyc
Also:
>
> AssertionError: b'Hello, World!' != 'Hello, World!'
Notice the "b" prefix on the first string. You are getting hung up by
the fact that one is a byte-string and the other is a unicode string.
In Python 2 this would have probably "just worked" but in Python 3 you
have to be more careful.
HTH.
*Randy Syring*
Husband | Father | Redeemed Sinner
/"For what does it profit a man to gain the whole world
and forfeit his soul?" (Mark 8:36 ESV)/
On 07/08/2015 11:33 PM, Paradox wrote:
> I am trying to learn TDD using the tutorial here:
>
> https://github.com/mjhea0/flaskr-tdd
>
> The only thing I have done differently from the tutorial is to use
> pyvenv rather than virtualenv and to use py.test for my test runner.
>
> When I get to the point of running the first test (on returning the
> "Hello, World!" page) the second time (after the app.py file is
> created and filled) it still fails as follows:
>
> app-test.py:1: in <module>
> from app import app
> app.py:1: in <module>
> from flask import Flask
> E ImportError: No module named 'flask'
>
> Running the flask app works fine, it starts the development server and
> returns the proper page, there seems to be something wrong with the
> test file or the test runner.
>
> Incidentally when I run the test without py.test it finds the module
> but fails with an error in the returned string:
>
> AssertionError: b'Hello, World!' != 'Hello, World!'
>
> I haven't figured that one out yet either!
>
> Is there a reason py.test can't find the flask module in the pyvenv
> created virtual environment?
>
> thomas
> ===============
> Thomas C. Hicks, MD, MPH
> Training Manager
> Gansu Gateway, Lanzhou, Gansu
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20150709/dd084f9d/attachment.htm>
More information about the testing-in-python
mailing list