Note that there are some explanatory texts on larger screens.

plurals
  1. POPyDev running pytest unit test with module-shared fixture fails
    primarykey
    data
    text
    <p>I have a problem running pytest unit tests with pyDev. I try to run a unit test with a module shared fixture and a finalizer which should be excecuted after the last test. But when running the unit test in pyDev it does not use the same instance but instead creates two different instances. The example is running fine in the console or when started from a script within pydev.</p> <p>I'm using platform Python 2.7.3, pytest-2.3.4, pyDev 2.7.3.2013031601, Eclipse 4.2 on Win7.</p> <p>I tried the example from <a href="http://pytest.org/latest/fixture.html">http://pytest.org/latest/fixture.html</a></p> <p>The output from pydev is:</p> <pre><code>============================= test session starts ============================== platform win32 -- Python 2.7.3 -- pytest-2.3.4 __________________________________ test_ehlo ___________________________________ smtp = &lt;smtplib.SMTP instance at 0x027F9080&gt; __________________________________ test_noop ___________________________________ smtp = &lt;smtplib.SMTP instance at 0x027FF3C8&gt; </code></pre> <p>The console output is:</p> <pre><code>============================= test session starts ============================== platform win32 -- Python 2.7.3 -- pytest-2.3.4 __________________________________ test_ehlo ___________________________________ smtp = &lt;smtplib.SMTP instance at 0x01E51288&gt; __________________________________ test_noop ___________________________________ smtp = &lt;smtplib.SMTP instance at 0x01E51288&gt; </code></pre> <p>Which is the expected behaviour. What am I doing wrong??</p> <p>the used code is conftest.py:</p> <pre><code>import pytest import smtplib @pytest.fixture(scope="module") def smtp(): return smtplib.SMTP("merlinux.eu") </code></pre> <p>The test code in test_smtplib.py:</p> <pre><code># content of test_module.py def test_ehlo(smtp): response = smtp.ehlo() assert response[0] == 250 assert "merlinux" in response[1] assert 0 # for demo purposes def test_noop(smtp): response = smtp.noop() assert response[0] == 250 assert 0 # for demo purposes </code></pre> <p>Running the test from script with:</p> <pre><code>import pytest,os os.chdir("[path_to_tests]/tests") #your file location pytest.main(['-s', 'test_smtplib.py']) </code></pre> <p>Any suggestions and thanks a lot for your help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload