Skip to content

Commit

Permalink
Merge pull request #98 from dimagi/pytest
Browse files Browse the repository at this point in the history
Run tests with pytest instead of nose
  • Loading branch information
millerdev authored Jan 2, 2025
2 parents 61d5311 + b335664 commit b7cdbec
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 71 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ on:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
python: ['3.9', '3.10', '3.11', '3.12', '3.13']
django:
- 'Django>=3.2,<3.3'
- 'Django>=4.1,<4.2'
- 'Django>=4.2,<4.3'
- 'Django>=5.0,<5.1'
- 'Django>=5.1,<5.2'
exclude:
- {python: '3.9', django: 'Django>=5.0,<5.1'}
- {python: '3.9', django: 'Django>=5.1,<5.2'}
services:
postgres:
image: postgres:latest
Expand All @@ -39,7 +43,7 @@ jobs:
run: |
python --version
pip install --upgrade pip wheel
pip install "${{ matrix.django }}" psycopg2-binary pynose flake8
pip install "${{ matrix.django }}" psycopg2-binary pytest-unmagic flake8
- name: Run tests
env:
DB_SETTINGS: >-
Expand All @@ -51,6 +55,6 @@ jobs:
"HOST":"localhost",
"PORT":"5432"
}
run: nosetests -v --capture_output
run: pytest -v
- name: Check style
run: flake8 django_cte/ tests/
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,26 @@ to use Common Table Expressions with the Django ORM.

```
cd django-cte
mkvirtualenv cte # or however you choose to setup your environment
pip install django pynose flake8
python -m venv .venv
source .venv/bin/activate
pip install django pytest-unmagic flake8
nosetests
pytest
flake8 --config=setup.cfg
# To run tests against postgres
pip install psycopg2-binary
psql -U username -h localhost -p 5432 -c 'create database django_cte;'
export PG_DB_SETTINGS='{
"ENGINE":"django.db.backends.postgresql_psycopg2",
"NAME":"django_cte",
"USER":"username",
"PASSWORD":"password",
"HOST":"localhost",
"PORT":"5432"}'
# WARNING pytest will delete the test_django_cte database if it exists!
DB_SETTINGS="$PG_DB_SETTINGS" pytest
```

All feature and bug contributions are expected to be covered by tests.
Expand Down
3 changes: 0 additions & 3 deletions django_cte/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from .cte import CTEManager, CTEQuerySet, With # noqa

__version__ = "1.3.3"
3 changes: 0 additions & 3 deletions django_cte/cte.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from django.db.models import Manager
from django.db.models.query import Q, QuerySet, ValuesIterable
from django.db.models.sql.datastructures import BaseTable
Expand Down
2 changes: 0 additions & 2 deletions django_cte/join.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from django.db.models.sql.constants import INNER


Expand Down
3 changes: 0 additions & 3 deletions django_cte/meta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import weakref

from django.db.models.expressions import Col, Expression
Expand Down
3 changes: 0 additions & 3 deletions django_cte/query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import django
from django.core.exceptions import EmptyResultSet
from django.db import connections
Expand Down
4 changes: 0 additions & 4 deletions django_cte/raw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals


def raw_cte_sql(sql, params, refs):
"""Raw CTE SQL
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import os
import re
from io import open
Expand Down
12 changes: 4 additions & 8 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import os

import django
from unmagic import fixture

# django setup must occur before importing models
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
Expand All @@ -12,10 +10,8 @@
from .django_setup import init_db, destroy_db # noqa


def setup():
"""Initialize database for nosetests"""
@fixture(autouse=__name__, scope="package")
def test_db():
init_db()


def teardown():
yield
destroy_db()
13 changes: 1 addition & 12 deletions tests/django_setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import sys

from django.db import connection

from .models import KeyPair, Region, Order
Expand All @@ -16,13 +11,7 @@ def init_db():
return
is_initialized = True

# replace sys.stdout for prompt to delete database
old_stdout = sys.stdout
sys.stdout = sys.__stdout__
try:
connection.creation.create_test_db(verbosity=0)
finally:
sys.stdout = old_stdout
connection.creation.create_test_db(verbosity=0, autoclobber=True)

setup_data()

Expand Down
3 changes: 0 additions & 3 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from django.db.models import (
CASCADE,
Model,
Expand Down
4 changes: 1 addition & 3 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import os
import json

Expand All @@ -20,3 +17,4 @@
INSTALLED_APPS = ["tests"]

SECRET_KEY = "test"
USE_TZ = False
4 changes: 0 additions & 4 deletions tests/test_cte.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from __future__ import print_function
from unittest import SkipTest

from django.db.models import IntegerField, TextField
Expand Down
4 changes: 0 additions & 4 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from __future__ import print_function
from django.db.models.expressions import F
from django.db.models.query import QuerySet
from django.test import TestCase
Expand Down
4 changes: 0 additions & 4 deletions tests/test_raw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

from django.db.models import IntegerField, TextField
from django.test import TestCase

Expand Down
4 changes: 0 additions & 4 deletions tests/test_recursive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

import pickle
from unittest import SkipTest

Expand Down

0 comments on commit b7cdbec

Please sign in to comment.