Created
December 25, 2014 18:35
-
-
Save poliarush/4e71f7e3d3dbf437cc25 to your computer and use it in GitHub Desktop.
How to create shared object instance thru fixture with pytest xdist
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
import pytest | |
from random import randint | |
import logging | |
import pickle | |
logging.basicConfig(filename="log.log", level=logging.INFO) | |
class App(object): | |
def __init__(self): | |
self.a = randint(0, 100) | |
logging.info("initialized {}".format(self)) | |
def method(self): | |
logging.info("method in app that print {}".format(self.a)) | |
def pytest_configure(config): | |
if not hasattr(config, "slaveinput"): | |
config.app = App() | |
def pytest_configure_node(node): | |
node.slaveinput["app"] = pickle.dumps(node.config.app) | |
@pytest.fixture(scope="session") | |
def app(request): | |
return pickle.loads(request.config.slaveinput["app"]) |
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
INFO:root:initialized <conftest.App object at 0x02B07470> | |
INFO:root:method in app that print 46 | |
INFO:root:method in app that print 46 | |
INFO:root:method in app that print 46 |
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
versions pytest-2.5.1, py-1.4.19, python-2.7.3.final.0 | |
cwd=d:\temp\pytest-parallel-run | |
args=['--debug', '-s', '-v', '-n3', 'test_something.py'] | |
finish pytest_cmdline_parse --> <_pytest.config.Config object at 0x02776490> [hook] | |
pytest_cmdline_main [hook] | |
config: <_pytest.config.Config object at 0x02776490> | |
pytest_plugin_registered [hook] | |
manager: <_pytest.config.PytestPluginManager object at 0x027604B0> | |
plugin: <Session 'pytest-parallel-run'> | |
pytest_configure [hook] | |
config: <_pytest.config.Config object at 0x02776490> | |
configured with mode set to 'rewrite' [assertion] | |
pytest_plugin_registered [hook] | |
manager: <_pytest.config.PytestPluginManager object at 0x027604B0> | |
plugin: <_pytest.terminal.TerminalReporter instance at 0x02BB23C8> | |
pytest_plugin_registered [hook] | |
manager: <_pytest.config.PytestPluginManager object at 0x027604B0> | |
plugin: <xdist.dsession.TerminalDistReporter instance at 0x02C2C3F0> | |
pytest_plugin_registered [hook] | |
manager: <_pytest.config.PytestPluginManager object at 0x027604B0> | |
plugin: <xdist.dsession.DSession instance at 0x02C26968> | |
pytest_sessionstart [hook] | |
session: <Session 'pytest-parallel-run'> | |
pytest_plugin_registered [hook] | |
manager: <_pytest.config.PytestPluginManager object at 0x027604B0> | |
plugin: <_pytest.python.FixtureManager instance at 0x02C2CAA8> | |
pytest_report_header [hook] | |
startdir: d:\temp\pytest-parallel-run | |
config: <_pytest.config.Config object at 0x02776490> | |
finish pytest_report_header --> ['plugins: xdist', ['using: pytest-2.5.1 pylib-1.4.19', 'setuptools registered plugins:', ' pytest-xdist-1.9 at c:\\Program Files (x86)\\Python27\\lib\\site-packages\\xdist\\plugin.pyc']] [hook] | |
pytest_xdist_setupnodes [hook] | |
config: <_pytest.config.Config object at 0x02776490> | |
specs: [<XSpec 'popen'>, <XSpec 'popen'>, <XSpec 'popen'>] | |
pytest_xdist_newgateway [hook] | |
gateway: <Gateway id='gw0' receive-live, 0 active channels> | |
pytest_xdist_newgateway [hook] | |
gateway: <Gateway id='gw1' receive-live, 0 active channels> | |
pytest_xdist_newgateway [hook] | |
gateway: <Gateway id='gw2' receive-live, 0 active channels> | |
setting up nodes [config:nodemanager] | |
new basetemp c:\users\poliar~1\appdata\local\temp\pytest-96 [config:tmpdir] | |
pytest_configure_node [hook] | |
node: <SlaveController gw0> | |
started node <SlaveController gw0> [config:nodemanager] | |
pytest_configure_node [hook] | |
node: <SlaveController gw1> | |
started node <SlaveController gw1> [config:nodemanager] | |
pytest_configure_node [hook] | |
node: <SlaveController gw2> | |
started node <SlaveController gw2> [config:nodemanager] | |
pytest_collection [hook] | |
session: <Session 'pytest-parallel-run'> | |
finish pytest_collection --> True [hook] | |
pytest_runtestloop [hook] | |
session: <Session 'pytest-parallel-run'> | |
pytest_testnodeready [hook] | |
node: <SlaveController gw1> | |
pytest_testnodeready [hook] | |
node: <SlaveController gw0> | |
pytest_testnodeready [hook] | |
node: <SlaveController gw2> | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists' when='setup' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists' when='setup' outcome='passed'> | |
finish pytest_report_teststatus --> ('', '', '') [hook] | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists3' when='setup' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists3' when='setup' outcome='passed'> | |
finish pytest_report_teststatus --> ('', '', '') [hook] | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists' when='call' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists' when='call' outcome='passed'> | |
finish pytest_report_teststatus --> ('passed', '.', 'PASSED') [hook] | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists3' when='call' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists3' when='call' outcome='passed'> | |
finish pytest_report_teststatus --> ('passed', '.', 'PASSED') [hook] | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists' when='teardown' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists' when='teardown' outcome='passed'> | |
finish pytest_report_teststatus --> ('', '', '') [hook] | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists3' when='teardown' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists3' when='teardown' outcome='passed'> | |
finish pytest_report_teststatus --> ('', '', '') [hook] | |
pytest_testnodedown [hook] | |
node: <SlaveController gw2> | |
error: None | |
pytest_testnodedown [hook] | |
node: <SlaveController gw0> | |
error: None | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists2' when='setup' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists2' when='setup' outcome='passed'> | |
finish pytest_report_teststatus --> ('', '', '') [hook] | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists2' when='call' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists2' when='call' outcome='passed'> | |
finish pytest_report_teststatus --> ('passed', '.', 'PASSED') [hook] | |
pytest_runtest_logreport [hook] | |
report: <TestReport 'test_something.py::test_exists2' when='teardown' outcome='passed'> | |
pytest_report_teststatus [hook] | |
report: <TestReport 'test_something.py::test_exists2' when='teardown' outcome='passed'> | |
finish pytest_report_teststatus --> ('', '', '') [hook] | |
pytest_testnodedown [hook] | |
node: <SlaveController gw1> | |
error: None | |
finish pytest_runtestloop --> True [hook] | |
pytest_sessionfinish [hook] | |
session: <Session 'pytest-parallel-run'> | |
exitstatus: 0 | |
pytest_terminal_summary [hook] | |
terminalreporter: <_pytest.terminal.TerminalReporter instance at 0x02BB23C8> | |
pytest_unconfigure [hook] | |
config: <_pytest.config.Config object at 0x02776490> | |
finish [config:tmpdir] |
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
import pytest | |
def test_exists(app): | |
app.method() | |
def test_exists2(app): | |
app.method() | |
def test_exists3(app): | |
app.method() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment