[pytest-dev] Not running standard pytest collector for file spec/*_spec.py

Bruno Oliveira nicoddemus at gmail.com
Mon Mar 12 15:10:12 EDT 2018


Hi Ringo,

It is as Ronny said, you can see the code responsible for that here:

https://github.com/pytest-dev/pytest/blob/master/_pytest/python.py#L162

When the file has a `.py` extension and is one of the "inipaths" (paths
given explicitly in the command line), then the `python` plugin will
collect that file anyway.

You can override this by implementing your own `pytest_collect_file` and
return non-`None` when a `.py` file inside the specs directory is passed in
the command-line.

Cheers,
Bruno.

On Mon, Mar 12, 2018 at 1:44 PM RonnyPfannschmidt <
opensource at ronnypfannschmidt.de> wrote:

> Hi Ringo,
>
> if pytest is given a explicit filename, it just goes for the file,
>
> even if it doesn't match the glob for python files when searching
> automatically
> -- Ronny
>
>
> Am 12.03.2018 um 17:08 schrieb Ringo De Smet:
>
> Hello,
>
> I am in the process of implementing a pytest plugin to run mamba tests as
> a pytest plugin. Running pytest without any arguments works correctly:
> pytest picks up tests using the python and unittest plugins from the tests
> folder and picks up the mamba tests from the spec folder.
>
> The problem starts when running pytest with a single spec file as argument:
>
> $ pytest spec/action_base_spec.py
> =======================================================================
> test session starts
> ========================================================================
> platform darwin -- Python 3.6.4, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
> rootdir: /Users/ringods/Projects/ontoforce/metis/execution_layer, inifile:
> plugins: mamba-1.0.0
> collected 6 items / 1 errors
>
> ==============================================================================
> ERRORS
> ==============================================================================
> ____________________________________________________________ ERROR
> collecting spec/action_base_spec.py
> _____________________________________________________________
> spec/action_base_spec.py:20: in <module>
>     with description('ActionBase') as self:
> E   AttributeError: __enter__
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted:
> 1 errors during collection
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> ===================================================================== 1
> error in 0.15 seconds
> ======================================================================
>
> This comes from the python plugin in pytest. When running with `-p
> no:python`, this command succeeds.
>
> Why is the python plugin picking up this file, even when it doesn't match
> the regexes `test_*.py` or `*_test.py`?
>
> Ringo
>
>
>
> _______________________________________________
> pytest-dev mailing listpytest-dev at python.orghttps://mail.python.org/mailman/listinfo/pytest-dev
>
>
> _______________________________________________
> pytest-dev mailing list
> pytest-dev at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20180312/ff4ec833/attachment-0001.html>


More information about the pytest-dev mailing list