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

2018-03-13 Thread Bruno Oliveira
Hi Ringo,

On Tue, Mar 13, 2018 at 4:40 AM Ringo De Smet 
wrote:

> Ronny, Bruno,
>
> On Mon, Mar 12, 2018 at 8:10 PM, Bruno Oliveira 
> wrote:
>
>> 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.
>>
>
> That's a pitty. Given the pluggability of pytest, each plugin could have a
> way to collect files and offer test suites back to pytest. Isn't there a
> way to specify one of my spec tests without the wrong plugin(s) picking up
> this file?
>

The only way I can think of right now is to pass `-p no:python` in the
command line to explicitly disable the Python plugin, as you mention.

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.
>>
>>
>  Bruno, my plugin is collecting the file specified on the command line
> correctly, but still the python plugin tries to run it too. That's where it
> goes wrong.
>

Oh my bad, indeed all return values of `pytest_collect_file` are processed.
This is by design, that allows `--doctest-modules` to process docstrings in
test files (for example).

But looking at your original error more closely:

```
spec/action_base_spec.py:20: in 
with description('ActionBase') as self:
E   AttributeError: __enter__
```

It is not clear to me why this is breaking because of the python plugin;
can you share `action_base_spec.py` and your plugin code?

Cheers,
Bruno.
___
pytest-dev mailing list
pytest-dev@python.org
https://mail.python.org/mailman/listinfo/pytest-dev


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

2018-03-12 Thread Bruno Oliveira
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 <
opensou...@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 
> 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@python.orghttps://mail.python.org/mailman/listinfo/pytest-dev
>
>
> ___
> pytest-dev mailing list
> pytest-dev@python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
>
___
pytest-dev mailing list
pytest-dev@python.org
https://mail.python.org/mailman/listinfo/pytest-dev