Code Monkey home page Code Monkey logo

Comments (7)

bubenkoff avatar bubenkoff commented on May 28, 2024

will check

On 10 September 2014 18:57, Robin Pedersen [email protected] wrote:

I have prepared a minimal case to demonstrate this issue:
https://github.com/ropez/pytest-bdd-issue

Having a conftest.py in a subdirectory, and the subdirectory also having
a init.py, the conftest module is evaluated twice. This is an
important issue, because any hooks added there, such as pytest_pyfunc_call,
will be registered twice, and called twice for each test case. This is
causing problems in our actual, much bigger, project.

Removing pytest-bdd from the equation, for instance by commenting out the
@Scenario decorator to make it a simple test function, removed the
problem. Also, running py.test inside the subdirectory, or deleting the
init.py file, removes the problem.


Reply to this email directly or view it on GitHub
#62.

Anatoly Bubenkov

from pytest-bdd.

bubenkoff avatar bubenkoff commented on May 28, 2024

and how do you run this example?
for me it works with np!

┌─[vagrant@paylogic-virtual] - [~/workspace/pytest-bdd-issue] - [2014-09-10
06:01:47]
└─[0] <git:(master 3f7452✈) > py.test foo -s

foo.conftest
===================================================================== test

session starts

platform linux2 -- Python 2.7.6 -- py-1.4.24 -- pytest-2.6.2
plugins: bdd, bdd
collecting 0 items
conftest
collected 1 items

foo/test_foo.py .

================================================================== 1 passed

in 0.01 seconds

On 10 September 2014 19:57, Anatoly Bubenkov [email protected] wrote:

will check

On 10 September 2014 18:57, Robin Pedersen [email protected]
wrote:

I have prepared a minimal case to demonstrate this issue:
https://github.com/ropez/pytest-bdd-issue

Having a conftest.py in a subdirectory, and the subdirectory also having
a init.py, the conftest module is evaluated twice. This is an
important issue, because any hooks added there, such as
pytest_pyfunc_call, will be registered twice, and called twice for each
test case. This is causing problems in our actual, much bigger, project.

Removing pytest-bdd from the equation, for instance by commenting out the
@Scenario decorator to make it a simple test function, removed the
problem. Also, running py.test inside the subdirectory, or deleting the
init.py file, removes the problem.


Reply to this email directly or view it on GitHub
#62.

Anatoly Bubenkov

Anatoly Bubenkov

from pytest-bdd.

ropez avatar ropez commented on May 28, 2024

I run it without the 'foo' argument: py.test -s

(obsiously, the example is simplified, but imagine that you also have other directories where you want to find tests, like bar/test_bar.py)

from pytest-bdd.

bubenkoff avatar bubenkoff commented on May 28, 2024

now i get it :)
looks like it's because of the custom mechanism of the conftest lookup
which pytest-bdd needs to get the feature folder base
so it imports conftests from the place where scenario is, and the module
name is different if you import it from inside or from outside of the
certain folder
but anyway, i've tried an example adding a hook handler, and it's called
only once:
https://github.com/bubenkoff/pytest-bdd-issue

are you sure you've checked and hooks called twice?

(bdd-issue)┌─[vagrant@paylogic-virtual] - [~/workspace/pytest-bdd-issue] -
[2014-09-11 07:54:46]
└─[1] <git:(master 498c1d✱✈) > py.test -s

test session starts

platform linux2 -- Python 2.7.6 -- py-1.4.24 -- pytest-2.6.2
plugins: bdd, bdd

foo.conftest
collecting 0 items
conftest
pytest_generate_tests hook
collected 1 items

foo/test_foo.py pytest_pyfunc_call hook
.

i'll think how to avoid this strange double collection anyway

On 11 September 2014 08:53, Robin Pedersen [email protected] wrote:

I run it without the 'foo' argument: py.test -s


Reply to this email directly or view it on GitHub
#62 (comment)
.

Anatoly Bubenkov

from pytest-bdd.

ropez avatar ropez commented on May 28, 2024

I added another conftest.py in the base directory. Now it's being called twice. We happen to have another conftest.py in our main project, for adding command line options that are "global" for all subdirectories.

For the simplified example, I only checked that the module was imported twice.

from pytest-bdd.

ropez avatar ropez commented on May 28, 2024

Btw, I have currently worked around this issue by separating all test files from python modules that are used as utilities in tests, and not having __init__.py files in the directories that contain tests. I'm fine with this, because I like the separation anyway.

from pytest-bdd.

bubenkoff avatar bubenkoff commented on May 28, 2024

would you mind creating a PR with the test reproducing this problem?
So i can easily work on the actual fix

On 11/09/2014, Robin Pedersen [email protected] wrote:

Btw, I have currently worked around this issue by separating all test files
from python modules that are used as utilities in tests, and not having
__init__.py files in the directories that contain tests. I'm fine with
this, because I like the separation anyway.


Reply to this email directly or view it on GitHub:
#62 (comment)

Anatoly Bubenkov

from pytest-bdd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.