-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
pytest run testfiles with same name in different directory will fail #3151
Comments
My project is an example: https://github.com/iqianxing/unittest-demos.git |
Ho @iqianxing, this is happening because your test files have the same name in two different directories, and they are imported into the global namespace because there's no `init files; there's a more detailed explanation in the docs. In this case you can either create |
@nicoddemus Thank you! |
Summary: pytest-dev/pytest#3151 If there isn't a __init__.py file in a directory, pytest imports a test file into the global namespace. This means in a package structure not including __init__.py files, test files in separate directories with the same basename (filename not including directory) will overlap, and fortunately pytest fails with a visible error message rather than not executing the tests. Differential Revision: D14031515 fbshipit-source-id: a6032e44eda2b32138235e2728925cf56fc24897
Summary: Pull Request resolved: #287 pytest-dev/pytest#3151 If there isn't a __init__.py file in a directory, pytest imports a test file into the global namespace. This means in a package structure not including __init__.py files, test files in separate directories with the same basename (filename not including directory) will overlap, and fortunately pytest fails with a visible error message rather than not executing the tests. Reviewed By: Titousensei Differential Revision: D14031515 fbshipit-source-id: dc0111b1fa62a630cf1be3da555632041ac7ba3c
This should hopefully fix pytest-dev/pytest#3151 as we have seen the following error on concourse: ``` import file mismatch: imported module 'test_notify_api_letter' has this __file__ attribute: /var/project/tests/functional/preview_and_dev/test_notify_api_letter.py which is not the same as the test file we want to collect: /var/project/tests/functional/staging_and_prod/notify_api/test_notify_api_letter.py HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules ```
init files everywhere and this is still an issue when your module your testing imports a library that as the same name as a library you are testing for another module |
Create a 'pytest.ini' file. Here's an example. [pytest] It's better to put all your test modules in to one package like this one. |
Also see the explanation in the docs here: https://docs.pytest.org/en/stable/goodpractices.html#tests-outside-application-code |
This fixes the tests failing with an error because they're importing two different `openstreetmap` modules from two different locations but getting confused between the two. There's an [issue comment][0] and a [documentation section][1] explaining this. Unfortunately adding the `--import-mode=importlib` option didn't fix the error so I had to use the `__init__.py` fix. Maybe it's a doctest specific thing. [0]: pytest-dev/pytest#3151 (comment) [1]: https://docs.pytest.org/en/latest/pythonpath.html#import-modes
…st/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…t/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…t/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…stenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…t/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…t/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…st/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…st/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…ist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…r dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
… dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…ist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…st/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
… for dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…s for dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…s for dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…rs for dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…t/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…dirs for dist/testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
…testenv [ commit 083eb89bb9af1e5570429a2580c0c2d5d136be4c ] this works around issues like pytest-dev/pytest#3151
It seems like using
https://docs.pytest.org/en/stable/explanation/goodpractices.html#tests-outside-application-code |
* Add basic MergeRequestManager Add a parser to parse open MergeRequests * Additional code for merge request manager * Add GitlabFilePersistence * Various fixes * Move things around to make code base easier to read * Various small fixes * Adding state handling By this, templates are not rendered, when they where rendered in the past and have not changed. Variable input is also taken into account for this. A state key is kept for each collection, a has is computed over the template content and the variable content * Adding tests for Merge Request Manager * Adding renderer tests * Adding tests for gitlab persistence * Fix wrong import * Test filenames need to be unique pytest-dev/pytest#3151 * Fix commit message, rename template_hash, since it's a hash of the collection * Slight adjustments Allow closing MRs Directly open MRs after closing them
Thanks for submitting an issue!
Here's a quick checklist in what to include:
The text was updated successfully, but these errors were encountered: