Skip to content

Commit

Permalink
Merge pull request #205 from praw-dev/pin_pytest
Browse files Browse the repository at this point in the history
Update pytest to 7.2
  • Loading branch information
LilSpazJoekp committed Nov 28, 2022
2 parents fb392dc + cad6e76 commit 259a2af
Show file tree
Hide file tree
Showing 39 changed files with 240 additions and 57 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"sphinxcontrib-trio",
],
"test": [
"asynctest >=0.13.0",
"asynctest >=0.13.0 ; python_version < '3.8'",
"mock >=0.8",
"pytest >=2.7.3",
"pytest ==7.2.*",
"pytest-asyncio",
"pytest-vcr",
"testfixtures >4.13.2, <7",
Expand Down
12 changes: 12 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
"""Async PRAW Test Suite."""
import sys

if sys.version_info < (3, 8):
from asynctest import TestCase

class BaseTest(TestCase):
"""Base class for Async PRAW tests."""

else:

class BaseTest:
"""Base class for Async PRAW tests."""


class HelperMethodMixin:
Expand Down
26 changes: 18 additions & 8 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
"""Async PRAW Integration test suite."""
import asyncio
import inspect
import logging

import aiohttp
import asynctest
import pytest

from asyncpraw import Reddit
from tests import HelperMethodMixin
from tests import BaseTest, HelperMethodMixin
from tests.conftest import vcr


class IntegrationTest(asynctest.TestCase, HelperMethodMixin):
class IntegrationTest(BaseTest, HelperMethodMixin):
"""Base class for Async PRAW integration tests."""

logger = logging.getLogger(__name__)

def setUp(self):
"""Setup runs before all test cases."""
@pytest.fixture(autouse=True)
def auto_close_reddit(self, event_loop):
yield
event_loop.run_until_complete(self.reddit.close())

def setup_method(self, method):
self._overrode_reddit_setup = True
self.setup_reddit()
self.setup_vcr()

async def tearDown(self) -> None:
await self.reddit.close()

def setup_vcr(self):
"""Configure VCR instance."""
self.recorder = vcr
Expand Down Expand Up @@ -103,3 +104,12 @@ def use_cassette(self, cassette_name=None, **kwargs):
def get_cassette_name(self) -> str:
function_name = inspect.currentframe().f_back.f_back.f_code.co_name
return f"{type(self).__name__}.{function_name}"

@pytest.fixture(autouse=True, scope="function")
def patch_sleep(self, monkeypatch):
"""Patch sleep to speed up tests."""

async def _sleep(*_, **__):
pass

monkeypatch.setattr(asyncio, "sleep", value=_sleep)
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_collections.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"""Test classes from collections.py."""

import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException, RedditAPIException
from asyncpraw.models import Submission
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_comment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import AsyncPRAWException, ClientException, RedditAPIException
from asyncpraw.models import Comment, Submission
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_draft.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException
from asyncpraw.models import Draft, Subreddit
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_emoji.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException
from asyncpraw.models import Emoji
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_live.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""Test asyncpraw.models.LiveThread"""
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.const import API_PATH
from asyncpraw.exceptions import RedditAPIException
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Message, Redditor, Subreddit, SubredditMessage

Expand Down
6 changes: 5 additions & 1 deletion tests/integration/models/reddit/test_modmail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys
from datetime import datetime

from asynctest import mock
if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import ModmailMessage, Subreddit

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/models/reddit/test_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


class TestMore(IntegrationTest):
async def setUp(self):
super().setUp()
def setup_method(self, method):
super().setup_method(method)
# Responses do not decode well on travis so manually renable gzip.
self.reddit._core._requestor._http._default_headers["Accept-Encoding"] = "gzip"

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/reddit/test_multi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Comment, Submission, Subreddit

Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_redditor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"""Test asyncpraw.models.redditor."""
import sys

import pytest
from asyncprawcore import Forbidden
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import RedditAPIException
from asyncpraw.models import Comment, Redditor, Submission
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_removal_reasons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException
from asyncpraw.models import RemovalReason
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_rules.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException, RedditAPIException
from asyncpraw.models import Rule
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_submission.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import RedditAPIException
from asyncpraw.models import Comment, Submission
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from aiohttp import ClientResponse
from aiohttp.http_websocket import WebSocketError
from asyncprawcore import BadRequest, Forbidden, NotFound, TooLarge
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.const import PNG_HEADER
from asyncpraw.exceptions import (
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/models/reddit/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
from os.path import abspath, dirname, join

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import (
Button,
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/reddit/test_wikipage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import sys
from base64 import urlsafe_b64encode

import pytest
from asyncprawcore import Forbidden, NotFound
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import RedditAPIException
from asyncpraw.models import Redditor, WikiPage
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/test_comment_forest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""Test asyncpraw.models.comment_forest."""
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import DuplicateReplaceException
from asyncpraw.models import Comment, MoreComments
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/test_inbox.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"""Test asyncpraw.models.inbox."""
import sys

import pytest
from asyncprawcore import Forbidden
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Comment, Message, Redditor, Subreddit

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/models/test_mod_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def test_create_note__thing_submission(self):
assert result_note.user == submission.author
assert result_note.note == "test note"

@mock.patch("time.sleep", return_value=None)
@mock.patch("asyncio.sleep", return_value=None)
async def test_delete_note(self, _):
self.reddit.read_only = False
with self.use_cassette():
Expand All @@ -57,7 +57,7 @@ async def test_delete_note(self, _):
notes = await self.async_list(subreddit.mod.notes.redditors(self.REDDITOR))
assert result_note not in notes

@mock.patch("time.sleep", return_value=None)
@mock.patch("asyncio.sleep", return_value=None)
async def test_delete_note__all_notes(self, _):
self.reddit.read_only = False
with self.use_cassette():
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/test_preferences.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Preferences

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/test_redditors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Test asyncpraw.models.redditors."""
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Redditor, Subreddit

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/test_subreddits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Test asyncpraw.models.subreddits."""
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Subreddit

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/test_trophy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Test asyncpraw.models.Trophy"""
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from .. import IntegrationTest

Expand Down
Loading

0 comments on commit 259a2af

Please sign in to comment.