-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,116 @@ | ||
def test_bar_fixture(pytester): | ||
|
||
def test_default_threads(pytester): | ||
"""Make sure that pytest accepts our fixture.""" | ||
|
||
# create a temporary pytest test module | ||
pytester.makepyfile(""" | ||
def test_sth(bar): | ||
assert bar == "europython2015" | ||
import pytest | ||
from threading import Lock | ||
class Counter: | ||
def __init__(self): | ||
self._count = 0 | ||
self._lock = Lock() | ||
def increase(self): | ||
with self._lock: | ||
self._count += 1 | ||
@pytest.fixture(scope='session') | ||
def counter(): | ||
return Counter() | ||
@pytest.mark.order(1) | ||
def test_thread_increase(counter): | ||
counter.increase() | ||
@pytest.mark.order(2) | ||
@pytest.mark.parallel_threads(1) | ||
def test_check_thread_count(counter): | ||
assert counter._count == 10 | ||
""") | ||
|
||
# run pytest with the following cmd args | ||
result = pytester.runpytest( | ||
'--foo=europython2015', | ||
'--parallel-threads=10', | ||
'-v' | ||
) | ||
|
||
# fnmatch_lines does an assertion internally | ||
result.stdout.fnmatch_lines([ | ||
'*::test_sth PASSED*', | ||
'*::test_check_thread_count PASSED*', | ||
]) | ||
|
||
# make sure that we get a '0' exit code for the testsuite | ||
assert result.ret == 0 | ||
|
||
|
||
def test_help_message(pytester): | ||
result = pytester.runpytest( | ||
'--help', | ||
) | ||
# fnmatch_lines does an assertion internally | ||
result.stdout.fnmatch_lines([ | ||
'run-parallel:', | ||
'*--foo=DEST_FOO*Set the value for the fixture "bar".', | ||
]) | ||
def test_marker(pytester): | ||
# create a temporary pytest test module | ||
pytester.makepyfile(""" | ||
import pytest | ||
from threading import Lock | ||
class Counter: | ||
def __init__(self): | ||
self._count = 0 | ||
self._lock = Lock() | ||
def test_hello_ini_setting(pytester): | ||
pytester.makeini(""" | ||
[pytest] | ||
HELLO = world | ||
""") | ||
def increase(self): | ||
with self._lock: | ||
self._count += 1 | ||
pytester.makepyfile(""" | ||
import pytest | ||
@pytest.fixture(scope='session') | ||
def counter(): | ||
return Counter() | ||
@pytest.fixture(scope='session') | ||
def counter2(): | ||
return Counter() | ||
@pytest.mark.order(1) | ||
def test_thread_increase(counter): | ||
counter.increase() | ||
@pytest.fixture | ||
def hello(request): | ||
return request.config.getini('HELLO') | ||
@pytest.mark.order(1) | ||
@pytest.mark.parallel_threads(5) | ||
def test_thread_increase_five(counter2): | ||
counter2.increase() | ||
def test_hello_world(hello): | ||
assert hello == 'world' | ||
@pytest.mark.order(2) | ||
@pytest.mark.parallel_threads(1) | ||
def test_check_thread_count(counter): | ||
assert counter._count == 10 | ||
@pytest.mark.order(2) | ||
@pytest.mark.parallel_threads(1) | ||
def test_check_thread_count(counter2): | ||
assert counter2._count == 5 | ||
""") | ||
|
||
result = pytester.runpytest('-v') | ||
# run pytest with the following cmd args | ||
result = pytester.runpytest( | ||
'--parallel-threads=10', | ||
'-v' | ||
) | ||
|
||
# fnmatch_lines does an assertion internally | ||
result.stdout.fnmatch_lines([ | ||
'*::test_hello_world PASSED*', | ||
'*::test_check_thread_count PASSED*', | ||
]) | ||
|
||
# make sure that we get a '0' exit code for the testsuite | ||
assert result.ret == 0 | ||
|
||
|
||
def test_help_message(pytester): | ||
result = pytester.runpytest( | ||
'--help', | ||
) | ||
# fnmatch_lines does an assertion internally | ||
result.stdout.fnmatch_lines([ | ||
'run-parallel:', | ||
' --parallel-threads=PARALLEL_THREADS' | ||
# ' Set the number of threads used to execute each test concurrently.', | ||
]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters