Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 0ba4a44

Browse files
authored
Merge pull request #480 from eregs/472-pytest
Replace nose with py.test
2 parents de66afe + 64c8119 commit 0ba4a44

16 files changed

Lines changed: 51 additions & 93 deletions

Gruntfile.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,6 @@ module.exports = function toExport(grunt) {
134134
},
135135
},
136136
},
137-
138-
shell: {
139-
'nose-chrome': {
140-
command: 'nosetests -s <%= config.testPath %> --tc=remote:chrome --tc=testUrl:<%= config.testUrl %>',
141-
options: {
142-
stdout: true,
143-
stderr: true,
144-
},
145-
},
146-
147-
'nose-ie11': {
148-
command: 'nosetests -s <%= config.testPath %> --tc=remote:ie11 --tc=testUrl:<%= config.testUrl %>',
149-
options: {
150-
stdout: true,
151-
stderr: true,
152-
},
153-
},
154-
},
155137
});
156138

157139
/* eslint-disable global-require,import/no-extraneous-dependencies */
@@ -172,8 +154,7 @@ module.exports = function toExport(grunt) {
172154
/**
173155
* Create task aliases by registering new tasks
174156
*/
175-
grunt.registerTask('nose', ['shell:nose-chrome', 'shell:nose-ie11']);
176-
grunt.registerTask('test', ['eslint', 'mocha_istanbul', 'nose']);
157+
grunt.registerTask('test', ['eslint', 'mocha_istanbul']);
177158
grunt.registerTask('test-js', ['eslint', 'mocha_istanbul']);
178159
grunt.registerTask('build-dev', ['env:dev', 'copy', 'browserify:dev', 'sass']);
179160
grunt.registerTask('build-dist', ['env:dist', 'copy', 'browserify:dist', 'sass', 'cssmin']);

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ Requirements are retrieved and/or build automatically via pip (see below).
3838
If running tests:
3939

4040
* mock - makes constructing mock objects/functions easy
41-
* django-nose - provides nosetest as a test runner
42-
* nose-exclude - allows certain directories to be excluded from nose
43-
* nose-testconfig - pass configuration data to tests; used to configure
44-
selenium tests
41+
* py.test - provides py.test as a test runner
4542
* coverage - provides test-coverage metrics
4643

4744
## Setup & Running
@@ -158,9 +155,9 @@ After you create a [Sauce Labs](https://saucelabs.com) account:
158155

159156
##### For functional tests
160157
- They also require having the environment serving data from ```dummy_api/```. To start the dummy API, from the root of your repo, run ```./dummy_api/start.sh 0.0.0.0:8282```.
161-
- The tests run using [nose](http://nose.readthedocs.org/en/latest/). If you wish to run the tests outside of the Grunt environment, you may by running ```nosetests regulations/uitests/*.py``` from the root of the repo.
162-
- By default, functional tests run using a local PhantomJS driver. To run using a different local browser, pass the `local` option, e.g. `tc=local:Chrome`; the option should be a webdriver class within the `selenium.webdriver` module.
163-
- To run tests using Sauce Labs, set the `remote` option to a key in `regulations.uitests.base_test:remote_configs`, e.g. `--tc=remote:ie11`. Alternatively, run `grunt nose` to run against all configured browsers on Sauce Labs, or `grunt shell:nose-chrome` to run against a single remote browser.
158+
- The tests run using [py.test](http://docs.pytest.org/en/latest/). If you wish to run the tests outside of the Grunt environment, you may by running ```py.test regulations/uitests/``` from the root of the repo.
159+
- By default, functional tests run using a local PhantomJS driver. To run using a different local browser, set a `UITESTS_LOCAL` environment variable, e.g. `UITESTS_LOCAL=Chrome`; the option should be a webdriver class within the `selenium.webdriver` module.
160+
- To run tests using Sauce Labs, set the `UITESTS_REMOTE` env variable to a key in `regulations.uitests.base_test:remote_configs`, e.g. `UITESTS_REMOTE=ie11`.
164161

165162
##### For unit tests
166163
- Unit tests do not require running the dummy API.

fr_notices/tests/navigation_tests.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import unicode_literals
33
from unittest import TestCase
44

5-
from nose.tools import assert_equal, assert_is_none
65
from mock import patch
76

87
from fr_notices import navigation
@@ -50,12 +49,12 @@ def test_footer(self):
5049
toc = navigation.make_preamble_nav(self.nodes)
5150

5251
nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-I')
53-
assert_equal(nav['next'].section_id, 'doc_id-preamble-doc_id-II')
54-
assert_is_none(nav['previous'])
52+
assert nav['next'].section_id == 'doc_id-preamble-doc_id-II'
53+
assert nav['previous'] is None
5554

5655
nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-II')
57-
assert_equal(nav['previous'].section_id, 'doc_id-preamble-doc_id-I')
58-
assert_is_none(nav['next'])
56+
assert nav['previous'].section_id == 'doc_id-preamble-doc_id-I'
57+
assert nav['next'] is None
5958

6059

6160
class CFRChangeBuilderTests(TestCase):
@@ -150,13 +149,13 @@ def test_footer(self):
150149
]
151150

152151
nav = navigation.footer([], toc, '2016_02749-cfr-478')
153-
assert_is_none(nav['previous'])
154-
assert_equal(nav['next'].section_id, '2016_02749-cfr-478-99')
152+
assert nav['previous'] is None
153+
assert nav['next'].section_id == '2016_02749-cfr-478-99'
155154

156155
nav = navigation.footer([], toc, '2016_02749-cfr-478-99')
157-
assert_equal(nav['previous'].section_id, '2016_02749-cfr-478')
158-
assert_equal(nav['next'].section_id, '2016_02749-cfr-478-120')
156+
assert nav['previous'].section_id == '2016_02749-cfr-478'
157+
assert nav['next'].section_id == '2016_02749-cfr-478-120'
159158

160159
nav = navigation.footer([], toc, '2016_02749-cfr-478-120')
161-
assert_equal(nav['previous'].section_id, '2016_02749-cfr-478-99')
162-
assert_is_none(nav['next'])
160+
assert nav['previous'].section_id == '2016_02749-cfr-478-99'
161+
assert nav['next'] is None

integration-tests.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ cd ..
88
cp local_settings_test.py local_settings.py
99
./run_server.sh &
1010
sleep 5
11-
grunt nose
11+
export UITESTS_URL=http://localhost:8000
12+
UITESTS_REMOTE=chrome py.test regulations/uitests -s
13+
UITESTS_REMOTE=ie11 py.test regulations/uitests -s

regulations/settings/base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@
170170
# Use the 'source' directory; useful for development
171171
JS_DEBUG = False
172172

173-
# Django by default tries to setup a databse when running tests. We don't have
174-
# a database, so we override the default test runner.
175-
TEST_RUNNER = 'regulations.tests.runner.DatabaselessTestRunner'
176-
177173
CACHES = {
178174
'default': {
179175
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',

regulations/settings/dev.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
CACHES['eregs_longterm_cache']['BACKEND'] = 'django.core.cache.backends.dummy.DummyCache'
77
CACHES['api_cache']['TIMEOUT'] = 5 # roughly per request
88

9-
INSTALLED_APPS += (
10-
'django_nose',
11-
)
12-
13-
NOSE_ARGS = [
14-
'--with-coverage',
15-
'--cover-package=fr_notices,regulations',
16-
'--exclude-dir=regulations/uitests'
17-
]
18-
199
try:
2010
from local_settings import *
2111
except ImportError:

regulations/tests/runner.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

regulations/tests/tasks_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from celery.exceptions import Retry, MaxRetriesExceededError
77
from django.conf import settings
88
from django.test import TestCase, override_settings
9-
from nose.tools import assert_equal
109
from requests.exceptions import RequestException
1110

1211
from regulations.tasks import submit_comment, cache_pdf, SignedUrl
@@ -126,7 +125,7 @@ def test_cache_pdf(self, s3_client, url_generate):
126125
url_generate.return_value = SignedUrl(
127126
'pdf', 'https://s3.amazonaws.com/bucket/pdf')
128127
url = cache_pdf('content', "1234_56", meta)
129-
assert_equal(url, url_generate.return_value)
128+
assert url == url_generate.return_value
130129
s3_client.put_object.assert_any_call(
131130
Body=json.dumps({'pdfUrl': meta.url}),
132131
Bucket=settings.ATTACHMENT_BUCKET,

regulations/tests/views_preamble_tests.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from unittest import TestCase
55
from datetime import date, timedelta
66

7-
from nose.tools import assert_equal
87
from django.http import Http404
98
from django.test import RequestFactory, override_settings
109

@@ -96,7 +95,7 @@ def test_comments_open_from_settings(self, ApiReader):
9695
"""
9796
_, meta, _ = preamble.notice_data('1')
9897

99-
assert_equal(meta['comment_state'], CommentState.OPEN)
98+
assert meta['comment_state'] == CommentState.OPEN
10099

101100
def _setup_mock_response(self, ApiReader, **kwargs):
102101
"""Mock the ApiReader response, replacing meta data fields with
@@ -124,21 +123,21 @@ def test_comments_open(self, ApiReader):
124123
future = date.today() + timedelta(days=10)
125124
self._setup_mock_response(ApiReader, comments_close=future.isoformat())
126125
_, meta, _ = preamble.notice_data('1')
127-
assert_equal(meta['comment_state'], CommentState.OPEN)
126+
assert meta['comment_state'] == CommentState.OPEN
128127

129128
@patch('regulations.views.preamble.ApiReader')
130129
def test_comments_prepub(self, ApiReader):
131130
future = date.today() + timedelta(days=10)
132131
self._setup_mock_response(ApiReader,
133132
publication_date=future.isoformat())
134133
_, meta, _ = preamble.notice_data('1')
135-
assert_equal(meta['comment_state'], CommentState.PREPUB)
134+
assert meta['comment_state'] == CommentState.PREPUB
136135

137136
@patch('regulations.views.preamble.ApiReader')
138137
def test_comments_closed(self, ApiReader):
139138
self._setup_mock_response(ApiReader)
140139
_, meta, _ = preamble.notice_data('1')
141-
assert_equal(meta['comment_state'], CommentState.CLOSED)
140+
assert meta['comment_state'] == CommentState.CLOSED
142141

143142
@patch('fr_notices.navigation.CFRChangeBuilder')
144143
@patch('regulations.generator.generator.api_reader')
@@ -153,8 +152,8 @@ def test_get_top_level_redirect(self, ApiReader, api_reader,
153152

154153
path = '/preamble/1'
155154
response = view(RequestFactory().get(path), paragraphs='1')
156-
assert_equal(response.status_code, 302)
157-
assert_equal(response.get('Location'), '/preamble/1/c')
155+
assert response.status_code == 302
156+
assert response.get('Location') == '/preamble/1/c'
158157

159158
@patch('regulations.views.preamble.ApiReader')
160159
def test_get_404(self, ApiReader):
@@ -187,7 +186,7 @@ def test_notice_data(self, ApiReader):
187186
for doc_id in ('123_456', '123-456'):
188187
preamble_, meta, notice = preamble.notice_data(doc_id)
189188
self.assertEqual(preamble_, self._mock_preamble)
190-
assert_equal(meta['comment_state'], CommentState.CLOSED)
189+
assert meta['comment_state'] == CommentState.CLOSED
191190
self.assertEqual(meta['cfr_refs'],
192191
[{'title': 21, 'parts': ['123']}])
193192
self.assertEqual(ApiReader.return_value.preamble.call_args[0][0],

regulations/uitests/base_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
from selenium import webdriver
3-
from testconfig import config
43

54

65
remote_configs = {
@@ -22,25 +21,25 @@ class BaseTest():
2221
job_name = 'eRegs UI Test'
2322

2423
def setUp(self):
25-
self.test_url = config['testUrl']
24+
self.test_url = os.environ['UITESTS_URL']
2625
self.driver = (
2726
self.make_remote()
28-
if 'remote' in config
27+
if 'UITESTS_REMOTE' in os.environ
2928
else self.make_local()
3029
)
3130
self.driver.set_window_size(800, 600)
3231
self.driver.implicitly_wait(30)
3332

3433
def make_local(self):
35-
attr = config.get('local', 'PhantomJS')
34+
attr = os.environ.get('UITESTS_LOCAL', 'PhantomJS')
3635
klass = getattr(webdriver, attr)
3736
if not isinstance(klass, type):
3837
raise TypeError(
3938
'Option {} did not resolve to a class'.format(attr))
4039
return klass()
4140

4241
def make_remote(self):
43-
selenium_config = remote_configs[config['remote']]
42+
selenium_config = remote_configs[os.environ['UITESTS_REMOTE']]
4443
capabilities = selenium_config['driver']
4544
if (os.environ.get('TRAVIS')
4645
and os.environ.get('TRAVIS_SECURE_ENV_VARS')):

0 commit comments

Comments
 (0)