Skip to content

Commit

Permalink
Upgrade pytest to 3.6.0
Browse files Browse the repository at this point in the history
pytest-dev/pytest#1875 made it impossible to declare
a function as a fixture multiple times, which we were doing across different
modules. The fix was to move our @pytest.fixture calls into decorators in the
tests/fixtures.py module.
  • Loading branch information
simonw committed May 31, 2018
1 parent 1639864 commit 9697717
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_version():
''',
setup_requires=['pytest-runner'],
tests_require=[
'pytest==3.2.1',
'pytest==3.6.0',
'aiohttp==2.3.2',
'beautifulsoup4==4.6.0',
],
Expand Down
6 changes: 5 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datasette.app import Datasette
import itertools
import os
import pytest
import random
import sqlite3
import sys
Expand All @@ -9,6 +10,7 @@
import time


@pytest.fixture(scope='session')
def app_client(sql_time_limit_ms=None, max_returned_rows=None, config=None):
with tempfile.TemporaryDirectory() as tmpdir:
filepath = os.path.join(tmpdir, 'test_tables.db')
Expand Down Expand Up @@ -39,11 +41,13 @@ def app_client(sql_time_limit_ms=None, max_returned_rows=None, config=None):
yield client


@pytest.fixture(scope='session')
def app_client_shorter_time_limit():
yield from app_client(20)


def app_client_returend_rows_matches_page_size():
@pytest.fixture(scope='session')
def app_client_returned_rows_matches_page_size():
yield from app_client(max_returned_rows=50)


Expand Down
12 changes: 4 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from .fixtures import (
from .fixtures import ( # noqa
app_client,
app_client_shorter_time_limit,
app_client_returend_rows_matches_page_size,
app_client_returned_rows_matches_page_size,
generate_compound_rows,
generate_sortable_rows,
METADATA,
)
import pytest
import urllib

pytest.fixture(scope='session')(app_client)
pytest.fixture(scope='session')(app_client_shorter_time_limit)
pytest.fixture(scope='session')(app_client_returend_rows_matches_page_size)


def test_homepage(app_client):
_, response = app_client.get('/.json')
Expand Down Expand Up @@ -936,11 +932,11 @@ def test_config_json(app_client):
} == response.json


def test_page_size_matching_max_returned_rows(app_client_returend_rows_matches_page_size):
def test_page_size_matching_max_returned_rows(app_client_returned_rows_matches_page_size):
fetched = []
path = '/test_tables/no_primary_key.json'
while path:
response = app_client_returend_rows_matches_page_size.get(
response = app_client_returned_rows_matches_page_size.get(
path, gather_request=False
)
fetched.extend(response.json['rows'])
Expand Down
8 changes: 4 additions & 4 deletions tests/test_html.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from bs4 import BeautifulSoup as Soup
from .fixtures import app_client, app_client_shorter_time_limit
from .fixtures import ( # noqa
app_client,
app_client_shorter_time_limit,
)
import pytest
import re
import urllib.parse

pytest.fixture(scope='session')(app_client)
pytest.fixture(scope='session')(app_client_shorter_time_limit)


def test_homepage(app_client):
response = app_client.get('/', gather_request=False)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from bs4 import BeautifulSoup as Soup
from .fixtures import (
from .fixtures import ( # noqa
app_client,
)
import pytest

pytest.fixture(scope='session')(app_client)


def test_plugins_dir_plugin(app_client):
response = app_client.get(
Expand Down

0 comments on commit 9697717

Please sign in to comment.