Skip to content

Commit

Permalink
prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergeileduc committed Nov 30, 2022
1 parent f2bd356 commit 8b90e56
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 46 deletions.
8 changes: 8 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# History

## 0.6.0

- First version for working with dpytest>=2.X.X
Changes have been made in backend, factories, websocket
- Change the README
- Change the setup.py for python >= 3.8
- Changing in doc

## 0.5.3

- Docs: Add vertical spacing for functions & methods
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__author__ = "Rune Tynan"
__license__ = "MIT"
__copyright__ = "Copyright 2018-2019 CraftSpider"
__version__ = "0.5.3"
__version__ = "0.6.0"

from . import backend
from .runner import *
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'CraftSpider'

# The full version, including alpha/beta/rc tags
release = '0.5.3'
release = '0.6.0'


# -- General configuration ---------------------------------------------------
Expand Down
93 changes: 64 additions & 29 deletions docs/tutorials/using_pytest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,50 @@ Putting all this together, we can rewrite our previous tests to look like this:

.. code:: python
import discord
import discord.ext.commands as commands
from discord.ext.commands import Cog, command
import pytest
import pytest_asyncio
import discord.ext.test as dpytest
@pytest.fixture
def bot(event_loop):
bot = ... # However you create your bot, make sure to use loop=event_loop
dpytest.configure(bot)
return bot
class Misc(Cog):
@command()
async def ping(self, ctx):
await ctx.send("Pong !")
@command()
async def echo(self, ctx, text: str):
await ctx.send(text)
@pytest_asyncio.fixture
async def bot():
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
b = commands.Bot(command_prefix="!",
intents=intents)
await b._async_setup_hook() # setup the loop
await b.add_cog(Misc())
dpytest.configure(b)
return b
@pytest.mark.asyncio
async def test_ping(bot):
await dpytest.message("!ping")
assert dpytest.verify().message().contains().content("Ping:")
assert dpytest.verify().message().content("Pong !")
@pytest.mark.asyncio
async def test_foo(bot):
await dpytest.message("!hello")
assert dpytest.verify().message().content("Hello World!")
async def test_echo(bot):
await dpytest.message("!echo Hello world")
assert dpytest.verify().message().contains().content("Hello")
Much less writing the same code over and over again, and tests will be automatically run by pytest, then the results
output in a nice pretty format once it's done.
Expand All @@ -66,25 +89,44 @@ An example ``conftest.py`` might look like this:

.. code:: python
import pytest
import glob
import os
import pytest_asyncio
import discord
import discord.ext.commands as commands
import discord.ext.test as dpytest
@pytest.fixture
def bot(event_loop):
bot = ... # However you create your bot, make sure to use loop=event_loop
dpytest.configure(bot)
return bot
@pytest_asyncio.fixture
async def bot():
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
b = commands.Bot(command_prefix="!",
intents=intents)
await b._async_setup_hook()
dpytest.configure(b)
return b
def pytest_sessionfinish():
# Clean up attachment files
files = glob.glob('./dpytest_*.dat')
for path in files:
@pytest_asyncio.fixture(autouse=True)
async def cleanup():
yield
await dpytest.empty_queue()
def pytest_sessionfinish(session, exitstatus):
""" Code to execute after all tests. """
# dat files are created when using attachements
print("\n-------------------------\nClean dpytest_*.dat files")
fileList = glob.glob('./dpytest_*.dat')
for filePath in fileList:
try:
os.remove(path)
except Exception as e:
print(f"Error while deleting file {path}: {e}")
os.remove(filePath)
except Exception:
print("Error while deleting file : ", filePath)
With that, you should be ready to use ``dpytest`` with your bot.

Expand All @@ -96,13 +138,6 @@ Troubleshooting
Make sure your tests take a parameter with the exact same name as the fixture,
pytest runs them based on name, including capitalization.

- I get an instance of my bot, but it just gets stuck / doesn't do anything
when I ``await``

Make sure you passed ``event_loop`` to your bot when creating it. Pytest-asyncio
does not necessarily use the default event loop, so your bot may not actually
be running.

--------------------

This is currently the end of the tutorials. Take a look at the `Runner Documentation`_ to see all the things you can
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.5.3
current_version = 0.6.0
commit = True
tag = True

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
url="https://github.com/CraftSpider/dpytest",
packages=["discord.ext.test"],
classifiers=[
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Development Status :: 3 - Alpha",
Expand Down
16 changes: 4 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import glob
import os
import pytest
import pytest_asyncio
import discord
import discord.ext.commands as commands
import discord.ext.test as test
import discord.ext.test as dpytest
from discord.client import _LoopSentinel


@pytest.fixture
def client(event_loop):
c = discord.Client(loop=event_loop)
test.configure(c)
return c


@pytest_asyncio.fixture
async def bot(request, event_loop):
async def bot(request):
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
Expand All @@ -36,14 +28,14 @@ async def bot(request, event_loop):
for extension in mark.args:
await b.load_extension("tests.internal." + extension)

test.configure(b)
dpytest.configure(b)
return b


@pytest_asyncio.fixture(autouse=True)
async def cleanup():
yield
await test.empty_queue()
await dpytest.empty_queue()


def pytest_sessionfinish(session, exitstatus):
Expand Down

0 comments on commit 8b90e56

Please sign in to comment.