Improve test a bit and add CHANGELOG entry
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
1.14.1.dev
|
1.15.0.dev
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
- new ``worker_id`` fixture, returns the id of the worker in a test or fixture.
|
||||||
|
Thanks Jared Hellman for the PR.
|
||||||
|
|
||||||
|
|
||||||
1.14
|
1.14
|
||||||
----
|
----
|
||||||
|
|||||||
@@ -195,6 +195,9 @@ a test or fixture, you may use the ``worker_id`` fixture to do so::
|
|||||||
""" use a different account in each xdist worker """
|
""" use a different account in each xdist worker """
|
||||||
return "account_%s" % worker_id
|
return "account_%s" % worker_id
|
||||||
|
|
||||||
|
When ``xdist`` is disabled (running with ``-n0`` for example), then
|
||||||
|
``worker_id`` will return ``"master"``.
|
||||||
|
|
||||||
Specifying test exec environments in an ini file
|
Specifying test exec environments in an ini file
|
||||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
|||||||
@@ -622,18 +622,23 @@ class TestNodeFailure:
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def test_worker_id_fixture(testdir):
|
@pytest.mark.parametrize('n', [0, 2])
|
||||||
|
def test_worker_id_fixture(testdir, n):
|
||||||
|
import glob
|
||||||
f = testdir.makepyfile("""
|
f = testdir.makepyfile("""
|
||||||
import pytest
|
import pytest
|
||||||
@pytest.mark.parametrize("run_num", [1,2])
|
@pytest.mark.parametrize("run_num", range(2))
|
||||||
def test_worker_id1(worker_id, run_num):
|
def test_worker_id1(worker_id, run_num):
|
||||||
with open("worker_id%s" % run_num, "w") as f:
|
with open("worker_id%s.txt" % run_num, "w") as f:
|
||||||
f.write(worker_id)
|
f.write(worker_id)
|
||||||
""")
|
""")
|
||||||
result = testdir.runpytest(f, "-n2")
|
result = testdir.runpytest(f, "-n%d" % n)
|
||||||
result.stdout.fnmatch_lines('* 2 passed in *')
|
result.stdout.fnmatch_lines('* 2 passed in *')
|
||||||
worker_ids = []
|
worker_ids = set()
|
||||||
for run_num in [1, 2]:
|
for fname in glob.glob(str(testdir.tmpdir.join("*.txt"))):
|
||||||
worker_id_file_path = testdir.tmpdir.join("worker_id%s" % run_num)
|
with open(fname) as f:
|
||||||
worker_ids.append(open(str(worker_id_file_path), "r").read())
|
worker_ids.add(f.read().strip())
|
||||||
assert "gw0" in worker_ids and "gw1" in worker_ids
|
if n == 0:
|
||||||
|
assert worker_ids == set(['master'])
|
||||||
|
else:
|
||||||
|
assert worker_ids == set(['gw0', 'gw1'])
|
||||||
|
|||||||
Reference in New Issue
Block a user