Skip to content

Commit

Permalink
test: use pytest
Browse files Browse the repository at this point in the history
setup.py test is deprecated, switch to pytest.

Also fix some tests that apparently weren't being run.
  • Loading branch information
pefoley2 committed May 31, 2021
1 parent a5503f1 commit 1cf2e90
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Ion.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ deploy
fabfile.py
manage.py
pyproject.toml
pytest.ini
requirements.txt
setup.py
.dependabot/config.yml
Expand Down
9 changes: 3 additions & 6 deletions ci/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ env:
pip install -U pip setuptools
pip install -U \
flake8 pylint pylint-django pylint-plugin-utils isort~=4.3 black==20.8b1 autopep8 \
coverage coveralls pyyaml
coveralls pyyaml pytest-django
pip install -U -r requirements.txt
echo "PATH=$PATH" >> $GITHUB_ENV
Expand Down Expand Up @@ -134,10 +134,7 @@ jobs:
- *copy_secret

- name: Regenerate workflow YAML file and check for changes
run: |
set -e
pip install pyyaml
./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py
run: ./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py

# Build docs/sources
- name: Build docs
Expand Down Expand Up @@ -239,7 +236,7 @@ jobs:

# Tests
- name: Run tests
run: coverage run ./setup.py test
run: coverage run -m pytest
- name: Migrate database
run: coverage run -a ./manage.py migrate
- name: Collect static files
Expand Down
4 changes: 2 additions & 2 deletions intranet/apps/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def test_api_eighth_signup_list(self):

def test_api_bus_list(self):
self.make_token()
route = Route.objects.create(route_name="JT-001", bus_number="JT-001")
route = Route.objects.create(route_name="JT-01", bus_number="JT-01")
response = self.client.get(reverse("api_bus_list"), HTTP_AUTHORIZATION=self.auth)

self.assertEqual(response.status_code, 200)
Expand All @@ -517,7 +517,7 @@ def test_api_bus_list(self):

def test_api_bus_detail(self):
self.make_token()
route_1 = Route.objects.create(route_name="JT-001", bus_number="JT-001")
route_1 = Route.objects.create(route_name="JT-01", bus_number="JT-01")
response = self.client.get(reverse("api_bus_detail", args=[route_1.pk]), HTTP_AUTHORIZATION=self.auth)

self.assertEqual(response.status_code, 200)
Expand Down
4 changes: 2 additions & 2 deletions intranet/apps/bus/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_bus(self):
m.assert_called()

def test_routes(self):
route = Route.objects.get_or_create(route_name="JT-101", bus_number="JT-101")[0]
route = Route.objects.get_or_create(route_name="JT-01", bus_number="JT-01")[0]
route.status = "a"
route.space = "_1"
route.save()
Expand All @@ -47,7 +47,7 @@ def test_routes(self):
self.assertEqual(route.space, "")

def test_route_representation(self):
route = Route.objects.get_or_create(route_name="JT-101", bus_number="JT-101")[0]
route = Route.objects.get_or_create(route_name="JT-01", bus_number="JT-01")[0]
route_str = str(route)

self.assertEqual(route.route_name, route_str)
10 changes: 5 additions & 5 deletions intranet/apps/eighth/tests/admin/test_admin_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_download_group_csv_view(self):
group = Group.objects.get_or_create(name="test group 5")[0]
user1 = get_user_model().objects.get_or_create(username="2021ttest", first_name="Tommy", last_name="Test", student_id=1234568)[0]
user2 = get_user_model().objects.get_or_create(username="2021ttest1", first_name="Thomas", last_name="Test", student_id=1234567)[0]
user3 = get_user_model().objects.get_or_create(username="2021awilliam", first_name="A", last_name="William", student_id=12345679)[0]
user3 = get_user_model().objects.get_or_create(username="2021awilliam", first_name="A", last_name="William", student_id=1234569)[0]
for member in [user1, user2, user3]:
member.groups.add(group)
member.save()
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_eighth_admin_signup_group(self):
username="2021awilliam",
first_name="A",
last_name="William",
student_id=12345679,
student_id=1234569,
user_type="student",
graduation_year=get_senior_graduation_year(),
)[0]
Expand Down Expand Up @@ -281,7 +281,7 @@ def test_eighth_admin_distribute_group(self):
username="2021awilliam",
first_name="A",
last_name="William",
student_id=12345679,
student_id=1234569,
user_type="student",
graduation_year=get_senior_graduation_year(),
)[0]
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_eighth_admin_distribute_unsigned(self):
username="2021awilliam",
first_name="A",
last_name="William",
student_id=12345679,
student_id=1234569,
user_type="student",
graduation_year=get_senior_graduation_year(),
)[0]
Expand Down Expand Up @@ -417,7 +417,7 @@ def test_eighth_admin_distribute_action(self):
username="2021awilliam",
first_name="A",
last_name="William",
student_id=12345679,
student_id=1234569,
user_type="student",
graduation_year=get_senior_graduation_year(),
)[0]
Expand Down
4 changes: 2 additions & 2 deletions intranet/apps/events/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_add_event(self):
"location": "Location",
"scheduled_activity": "",
"announcement": "",
"groups": 1,
"groups": [],
"show_attending": "on",
"show_on_dashboard": "on",
"category": "sports",
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_modify_event(self):
"location": "New location",
"scheduled_activity": "",
"announcement": "",
"groups": 1,
"groups": [],
"show_attending": "on",
"show_on_dashboard": "on",
"category": "sports",
Expand Down
2 changes: 1 addition & 1 deletion intranet/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
PRODUCTION = os.getenv("PRODUCTION", "").upper() == "TRUE"
IN_CI = any(os.getenv(key, "").upper() == "TRUE" for key in ["TRAVIS", "GITHUB_ACTIONS"])
# FIXME: figure out a less-hacky way to do this.
TESTING = "test" in sys.argv
TESTING = "test" in sys.argv and not IN_CI
LOGGING_VERBOSE = PRODUCTION

# Whether to report master password attempts
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
DJANGO_SETTINGS_MODULE = intranet.settings
python_files = tests.py test_*.py

0 comments on commit 1cf2e90

Please sign in to comment.