Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot disable capturing with --dist=distmode #680

Closed
pytestbot opened this issue Feb 13, 2015 · 11 comments
Closed

Cannot disable capturing with --dist=distmode #680

pytestbot opened this issue Feb 13, 2015 · 11 comments
Labels
plugin: xdist related to the xdist external plugin type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Lucas Cimon (BitBucket: LucasC, GitHub: LucasC)


To reproduce this issue, create a file named stupid_test.py with the following code :

def test_unicode():
    print "*[PRINT TO STDOUT]*"
    assert True

Then run the following:

$ py.test -v --capture=no --tx='1*popen' --dist=no stupid_test.py
# -> standard output contains "*[PRINT TO STDOUT]*"
$ py.test -v --capture=no --tx='1*popen' --dist=load stupid_test.py
# -> standard output is captured
$ py.test -v --capture=no --tx='1*popen' --dist=each stupid_test.py
# -> standard output is captured

I'm using the following version:

platform linux2 -- Python 2.7.6 -- py-1.4.26 -- pytest-2.6.4 -- /usr/bin/python

@pytestbot
Copy link
Contributor Author

Original comment by Lucas Cimon (BitBucket: LucasC, GitHub: LucasC):


I had a quick look on how are nodes set up in pytest-xdist slavemanage.py.
It looks like stdout / stderr could be aggregated & redirected using the method described in this pytest-dev thread and attachment by @hpk42.

Would that be a reasonable solution ?

@pytestbot
Copy link
Contributor Author

Original comment by Ragnar Rova (BitBucket: ragnar_rova, GitHub: ragnar_rova):


I have a similar issue, running tests that run fabric like so:

py.test -s -n4 --boxed

...

#!python

fabric_env/lib/python2.7/site-packages/fabric/io.py:211: in input_loop
    r, w, x = select([sys.stdin], [], [], 0.0)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <_pytest.capture.DontReadFromInput instance at 0x1053563b0>

    def fileno(self):
>       raise ValueError("redirected Stdin is pseudofile, has no fileno()")
E       ValueError: redirected Stdin is pseudofile, has no fileno()

fabric_env/lib/python2.7/site-packages/_pytest/capture.py:441: ValueError

@pytestbot
Copy link
Contributor Author

Original comment by Ragnar Rova (BitBucket: ragnar_rova, GitHub: ragnar_rova):


This got me halfway, but introduced other errors: http://stackoverflow.com/questions/27006884/pytest-xdist-without-capturing-output

@pytestbot pytestbot added type: bug problem that needs to be addressed plugin: xdist related to the xdist external plugin labels Jun 15, 2015
@szevzol
Copy link

szevzol commented Jun 18, 2015

I would like to do the same, disabling capture while using --dist-load.

I was able to do this by logging everything in my tests to STDERR. It was working fine until pytest release 2.6.0. In that release commit ce8678e modified something, which I don't understand yet. After that I cannot disable capturing at all with --dist=load.

Can anyone please help me to understand why it is not possible to disable capturing when distributing tests? Maybe there's a good reason I'm not aware of.

@nicoddemus
Copy link
Member

Can anyone please help me to understand why it is not possible to disable capturing when distributing tests? Maybe there's a good reason I'm not aware of.

I don't think is there any specific reason for that: I think it works like this because that's how the pytest runner works by default, and each slave uses the default option for capturing. I think all it is required is for the master node to pass that configuration along to the slaves.

@szevzol
Copy link

szevzol commented Jun 19, 2015

Thank you nicoddemus! I'm going to dig deeper in xdist and pytest to figure out the solution ;)

@szevzol
Copy link

szevzol commented Jun 19, 2015

This got me halfway, but introduced other errors: http://stackoverflow.com/questions/27006884/pytest-xdist-without-capturing-output

This suggestion is working for me however

  • it always turns off capturing.
  • it only prints STDERR but not STDOUT

If I do this:

capman._method = str(config.getoption("--capture"))

Instead of this:

capman._method = "no"

Then I can turn on and off capturing STDERR during distributed tests.

@nicoddemus
Copy link
Member

Fixed in #1124

jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Apr 14, 2016
2.9.1
=====

**Bug Fixes**

* Improve error message when a plugin fails to load.
  Thanks `@nicoddemus`_ for the PR.

* Fix (`#1178 <https://github.com/pytest-dev/pytest/issues/1178>`_):
  ``pytest.fail`` with non-ascii characters raises an internal pytest error.
  Thanks `@nicoddemus`_ for the PR.

* Fix (`#469`_): junit parses report.nodeid incorrectly, when params IDs
  contain ``::``. Thanks `@tomviner`_ for the PR (`#1431`_).

* Fix (`#578 <https://github.com/pytest-dev/pytest/issues/578>`_): SyntaxErrors
  containing non-ascii lines at the point of failure generated an internal
  py.test error.
  Thanks `@asottile`_ for the report and `@nicoddemus`_ for the PR.

* Fix (`#1437`_): When passing in a bytestring regex pattern to parameterize
  attempt to decode it as utf-8 ignoring errors.

* Fix (`#649`_): parametrized test nodes cannot be specified to run on the command line.


.. _#1437: pytest-dev/pytest#1437
.. _#469: pytest-dev/pytest#469
.. _#1431: pytest-dev/pytest#1431
.. _#649: pytest-dev/pytest#649

.. _@asottile: https://github.com/asottile


2.9.0
=====

**New Features**

* New ``pytest.mark.skip`` mark, which unconditionally skips marked tests.
  Thanks `@MichaelAquilina`_ for the complete PR (`#1040`_).

* ``--doctest-glob`` may now be passed multiple times in the command-line.
  Thanks `@jab`_ and `@nicoddemus`_ for the PR.

* New ``-rp`` and ``-rP`` reporting options give the summary and full output
  of passing tests, respectively. Thanks to `@codewarrior0`_ for the PR.

* ``pytest.mark.xfail`` now has a ``strict`` option, which makes ``XPASS``
  tests to fail the test suite (defaulting to ``False``). There's also a
  ``xfail_strict`` ini option that can be used to configure it project-wise.
  Thanks `@rabbbit`_ for the request and `@nicoddemus`_ for the PR (`#1355`_).

* ``Parser.addini`` now supports options of type ``bool``.
  Thanks `@nicoddemus`_ for the PR.

* New ``ALLOW_BYTES`` doctest option. This strips ``b`` prefixes from byte strings
  in doctest output (similar to ``ALLOW_UNICODE``).
  Thanks `@jaraco`_ for the request and `@nicoddemus`_ for the PR (`#1287`_).

* Give a hint on ``KeyboardInterrupt`` to use the ``--fulltrace`` option to show the errors.
  Fixes `#1366`_.
  Thanks to `@hpk42`_ for the report and `@RonnyPfannschmidt`_ for the PR.

* Catch ``IndexError`` exceptions when getting exception source location.
  Fixes a pytest internal error for dynamically generated code (fixtures and tests)
  where source lines are fake by intention.

**Changes**

* **Important**: `py.code <http://pylib.readthedocs.org/en/latest/code.html>`_ has been
  merged into the ``pytest`` repository as ``pytest._code``. This decision
  was made because ``py.code`` had very few uses outside ``pytest`` and the
  fact that it was in a different repository made it difficult to fix bugs on
  its code in a timely manner. The team hopes with this to be able to better
  refactor out and improve that code.
  This change shouldn't affect users, but it is useful to let users aware
  if they encounter any strange behavior.

  Keep in mind that the code for ``pytest._code`` is **private** and
  **experimental**, so you definitely should not import it explicitly!

  Please note that the original ``py.code`` is still available in
  `pylib <http://pylib.readthedocs.org>`_.

* ``pytest_enter_pdb`` now optionally receives the pytest config object.
  Thanks `@nicoddemus`_ for the PR.

* Removed code and documentation for Python 2.5 or lower versions,
  including removal of the obsolete ``_pytest.assertion.oldinterpret`` module.
  Thanks `@nicoddemus`_ for the PR (`#1226`_).

* Comparisons now always show up in full when ``CI`` or ``BUILD_NUMBER`` is
  found in the environment, even when ``-vv`` isn't used.
  Thanks `@The-Compiler`_ for the PR.

* ``--lf`` and ``--ff`` now support long names: ``--last-failed`` and
  ``--failed-first`` respectively.
  Thanks `@MichaelAquilina`_ for the PR.

* Added expected exceptions to ``pytest.raises`` fail message.

* Collection only displays progress ("collecting X items") when in a terminal.
  This avoids cluttering the output when using ``--color=yes`` to obtain
  colors in CI integrations systems (`#1397`_).

**Bug Fixes**

* The ``-s`` and ``-c`` options should now work under ``xdist``;
  ``Config.fromdictargs`` now represents its input much more faithfully.
  Thanks to `@bukzor`_ for the complete PR (`#680`_).

* Fix (`#1290`_): support Python 3.5's ``@`` operator in assertion rewriting.
  Thanks `@Shinkenjoe`_ for report with test case and `@tomviner`_ for the PR.

* Fix formatting utf-8 explanation messages (`#1379`_).
  Thanks `@biern`_ for the PR.

* Fix `traceback style docs`_ to describe all of the available options
  (auto/long/short/line/native/no), with `auto` being the default since v2.6.
  Thanks `@hackebrot`_ for the PR.

* Fix (`#1422`_): junit record_xml_property doesn't allow multiple records
  with same name.

.. _`traceback style docs`: https://pytest.org/latest/usage.html#modifying-python-traceback-printing

.. _#1422: pytest-dev/pytest#1422
.. _#1379: pytest-dev/pytest#1379
.. _#1366: pytest-dev/pytest#1366
.. _#1040: pytest-dev/pytest#1040
.. _#680: pytest-dev/pytest#680
.. _#1287: pytest-dev/pytest#1287
.. _#1226: pytest-dev/pytest#1226
.. _#1290: pytest-dev/pytest#1290
.. _#1355: pytest-dev/pytest#1355
.. _#1397: pytest-dev/pytest#1397
.. _@biern: https://github.com/biern
.. _@MichaelAquilina: https://github.com/MichaelAquilina
.. _@bukzor: https://github.com/bukzor
.. _@hpk42: https://github.com/hpk42
.. _@nicoddemus: https://github.com/nicoddemus
.. _@jab: https://github.com/jab
.. _@codewarrior0: https://github.com/codewarrior0
.. _@jaraco: https://github.com/jaraco
.. _@The-Compiler: https://github.com/The-Compiler
.. _@Shinkenjoe: https://github.com/Shinkenjoe
.. _@tomviner: https://github.com/tomviner
.. _@RonnyPfannschmidt: https://github.com/RonnyPfannschmidt
.. _@rabbbit: https://github.com/rabbbit
.. _@hackebrot: https://github.com/hackebrot
@nitrocode
Copy link

I'm using -n3 -d and each of my tests have print statements that are ignored by pytest. Im using pytest 2.9.1 and pytest-xdist-1.14.

py.test -sv -rx --color=yes -n3 -d --junit-xml=output.xml
py.test -sv -rx --color=yes -n3 -d --junit-xml=output.xml --capture=no

How do I see stdout? Doesn't appear in my junit xml file either when I'm parallelizing the tests.

@mloskot
Copy link

mloskot commented Jun 3, 2016

I'm using 2.9.1 on Windows with Python 3.5 and, similarly to @nitrocode, I also can not see my print outputs while using -n N. Running without xdist prints output to console as expected.

@RonnyPfannschmidt
Copy link
Member

currently cdist and nocapture is not compatible, the next major version of xdist will be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: xdist related to the xdist external plugin type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

6 participants