Skip to content

Commit c2ac2bc

Browse files
committed
Added test for Xdist
Closes #230
1 parent ee202c9 commit c2ac2bc

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

requirements_dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
mock
2+
pytest-xdist
23
requests==2.24.0

requirements_pub.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ coverage==5.2
88
Sphinx==3.3.0
99
twine==3.1.1
1010
pytest
11+
pytest-xdist
1112
mock==4.0.1
1213
pytest-runner==5.2

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
setup_requirements = ['pytest-runner', ]
2020

21-
test_requirements = ['pytest', ]
21+
test_requirements = ['pytest', 'pytest-xdist']
2222

2323
setup(
2424
author="LaserPhaser",
@@ -29,7 +29,6 @@
2929
'Intended Audience :: Developers',
3030
'License :: OSI Approved :: MIT License',
3131
'Natural Language :: English',
32-
'Programming Language :: Python :: 2.7',
3332
'Programming Language :: Python :: 3.6',
3433
'Programming Language :: Python :: 3.7',
3534
'Programming Language :: Python :: 3.8',
@@ -50,6 +49,7 @@
5049
url='https://github.com/pytest-dev/pytest-messenger',
5150
version='3.1.0',
5251
zip_safe=False,
52+
python_requires='>=3.6',
5353
entry_points={
5454
'pytest11': [
5555
'pytest-messenger = pytest_messenger.plugin',

tests/test_slack.py

+62
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,65 @@ def test_pass():
310310
'--slack_failed_emoji', slack_hook_icon_emoji,
311311
'--only_failed', True)
312312
assert mock_post.call_args is None
313+
314+
315+
def test_xdist_count(testdir):
316+
"""Make sure that our pytest-messenger works."""
317+
318+
testdir.makepyfile(
319+
"""
320+
import pytest
321+
def test_pass_1():
322+
assert 1 == 1
323+
324+
def test_pass_2():
325+
assert 1 == 1
326+
327+
def test_pass_3():
328+
assert 1 == 1
329+
330+
def test_pass_4():
331+
assert 1 == 1
332+
333+
def test_pass_5():
334+
assert 1 == 1
335+
336+
def test_pass_6():
337+
assert 1 == 1
338+
339+
def test_pass_7():
340+
assert 1 == 1
341+
342+
def test_fail_8():
343+
assert 1 == 0
344+
"""
345+
)
346+
347+
slack_hook_host = 'http://test.com/any_hash'
348+
slack_hook_username = 'regression Testing'
349+
slack_hook_report_host = 'http://report_link.com'
350+
slack_hook_channel = 'test'
351+
slack_hook_icon_emoji = ':thumbsdown:'
352+
expected_text = '<http://report_link.com|Passed=7 Failed=1 Skipped=0 Error=0 XFailed=0 XPassed=0>'
353+
with mock.patch('requests.post') as mock_post:
354+
testdir.runpytest('-n', '2',
355+
'--slack_channel', slack_hook_channel,
356+
'--slack_hook', slack_hook_host,
357+
'--slack_report_link', slack_hook_report_host,
358+
'--slack_username', slack_hook_username,
359+
'--slack_failed_emoji', slack_hook_icon_emoji)
360+
361+
called_data = json.loads(mock_post.call_args[1]['data'])
362+
called_host = mock_post.call_args[0][0]
363+
called_channel = called_data['channel']
364+
called_username = called_data['username']
365+
text = called_data['attachments'][0]['text']
366+
color = called_data['attachments'][0]['color']
367+
emoji = called_data['icon_emoji']
368+
369+
assert called_host == slack_hook_host
370+
assert text == expected_text
371+
assert called_channel == slack_hook_channel
372+
assert called_username == slack_hook_username
373+
assert color == '#ff0000'
374+
assert emoji == slack_hook_icon_emoji

0 commit comments

Comments
 (0)