Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Python 3 support #27

Closed
pelme opened this Issue · 14 comments

4 participants

Andreas Pelme Floris Bruynooghe Gustavo Picón Rafal Stozek
Andreas Pelme
Owner

With Django 1.5 around the corner, we should support Python 3 too!

Floris Bruynooghe
Owner

What shall we do about python 2.5? Given that we spent some effort on it for this release we probably want to keep it? This would mean something like this to catch exceptions:

try:
    raise Exception('oops')
except Exception:
    type, value = sys.exc_info()[:2]

I'm happy to live with this if it's fine by you.

Andreas Pelme
Owner

I think we should support Python 2.5.

py.test itself supports 2.4+, so it shouldn't really be a problem for us I guess. According to the IRC discussion yesterday, 2.5 support should be possible without too much hassle! Such exceptions is fine by me too if necessary.

Andreas Pelme
Owner

Btw, I think tabo will start working on Python 3 support!

Gustavo Picón

I commited my progress in tabo@df3a806

There are still failing tests in python3, but it is a start. I updated the code to make it work with python 2.5-3.3 and django 1.3-1.5. For this reason I didn't use django 1.5's helpers but pylib's, that are a bit more verbose but work well.

Comment on uglyness: request.content returns bytes in python3, not text. I chose to turn these bytes into strings instead of turning the expected strings into bytes to avoid dealing with encoding in pytest_django's tests, but it could be done that way too.

On failing tests: the tests that are failing are everything related to fixtures. The fixtures are simply not being loaded. And I think this is related to the problem I had when I tested pytest_django for django-treebeard: I couldn't run my old unit tests because pytest_django complained about the lack of a django_db mark. I'm seeing the same error in the tests.

Andreas Pelme
Owner

I just added Django 1.5 support (5592a69), it is mostly the same changes that you already made in this branch, but without the py3 stuff. I hope this will help a bit!

Rafal Stozek

Just want to let you know that I'm working on Python 3 support.

My branch: https://github.com/rafales/pytest_django/tree/python3-support

So far it's passing all tests.

Tox:

  py25-1.3.X: commands succeeded
  py33-1.5.X: commands succeeded
  py27-1.3.X: commands succeeded
  pypy-1.5.X: commands succeeded
  pypy-1.4.X: commands succeeded
  py27-1.5.X: commands succeeded
  py26-1.3.X: commands succeeded
  py32-1.5.X: commands succeeded
  py27-1.4.X: commands succeeded
  py26-1.4.X: commands succeeded
  py25-1.4.X: commands succeeded
  pypy-1.3.X: commands succeeded
  py26-1.5.X: commands succeeded
  congratulations :)

Python 2.5:

(py25django)rafal@mint pytest_django $ django-admin.py --version
1.4.3
(py25django)rafal@mint pytest_django $ python -V
Python 2.5.6
(py25django)rafal@mint pytest_django $ py.test tests/ -q
...................s............................x.....................
(py25django)rafal@mint pytest_django $ py.test tests/ -q --ds=tests.settings_mysql
................................................x.....................
(py25django)rafal@mint pytest_django $ py.test tests/ -q --ds=tests.settings_postgres
................................................x.....................

Python 2.6:

(py26django)rafal@mint pytest_django $ django-admin.py --version
1.5c1
(py26django)rafal@mint pytest_django $ python -V
Python 2.6.8
(py26django)rafal@mint pytest_django $ py.test tests/ -q 
...................s............................x.....................
(py26django)rafal@mint pytest_django $ py.test tests/ -q --ds=tests.settings_mysql
................................................x.....................
(py26django)rafal@mint pytest_django $ py.test tests/ -q --ds=tests.settings_postgres
................................................x.....................

Python 2.7:

(py27django)rafal@mint pytest_django $ django-admin.py --version
1.5c1
(py27django)rafal@mint pytest_django $ python -V
Python 2.7.3
(py27django)rafal@mint pytest_django $ py.test tests/ -q 
...................s............................x.....................
(py27django)rafal@mint pytest_django $ py.test tests/ -q --ds=tests.settings_mysql
................................................x.....................
(py27django)rafal@mint pytest_django $ py.test tests/ -q --ds=tests.settings_postgres
................................................x.....................

Python 3.2:

(py3django)rafal@mint pytest_django $ django-admin.py --version
1.5c1
(py3django)rafal@mint pytest_django $ python -V
Python 3.2.3
(py3django)rafal@mint pytest_django $ py.test tests/ -q
...................s............................x.....................
(py3django)rafal@mint pytest_django $ py.test tests/ -q --ds=tests.settings_postgres
................................................x.....................

Python 3.3:

(py33django)rafal@mint pytest_django $ django-admin.py --version
1.5c1
(py33django)rafal@mint pytest_django $ python -V
Python 3.3.0
(py33django)rafal@mint pytest_django $ py.test tests/ -q
...................s............................x.....................
(py33django)rafal@mint pytest_django $ py.test tests/ -q --ds=tests.settings_postgres
................................................x.....................

There's still some work to be done (for example I'll have to update travis config file). I'll send pull request when I'm done.

Andreas Pelme
Owner

That is good to hear.. I'm really looking forward to Python 3 support!

Rafal Stozek

Any idea how to measure test coverage? I get really strange results with pytest-cov.

Andreas Pelme
Owner

The problem might be caused by the tests that invoke new instances of py.test, since it is a new interpreter. I'm not sure it is possible to cover such calls with coverage.

Rafal Stozek

I didn't come up with any idea how to measure test coverage.

So far my branch works perfectly with:

So I'm getting more confident about my branch.

Do you know any other projects using pytest-django?

Rafal Stozek

I managed to measure coverage (the key was to stop using pytest-cov):

http://dl.dropbox.com/u/1623979/pytest-django-coverage/index.html

It looks like client and deprecated modules are not even imported.

Andreas Pelme
Owner

Thanks for the coverage stats. The test coverage looks better than I anticipated. When I started the fork there were no tests at all. :) No one ever complained about the deprecated modules, and given that they are totally broken, I think we should just get rid of them.

I just ran my own test suite with ~1500 tests, mixed with live_server, django_db etc, it runs just fine!

I used to github code search to find some repositories which uses pytest-django and found these:

https://github.com/dcramer/django-static-compiler
https://github.com/dcramer/django-view-as
https://github.com/birdsarah/django-actionitems
https://github.com/getsentry/raven-python
https://github.com/imankulov/django-template

I haven't run those test suites, but if someone has some time to spare they could be a good benchmark.

Everything looks good to me, are there anything that you think should be done before merging this to master and rolling a new release?

Rafal Stozek

I think we're good to go. I'll just write a new travis config and make a pull request.

Andreas Pelme
Owner

This is now merged and released in 2.2.0!

Andreas Pelme pelme closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.