-
Notifications
You must be signed in to change notification settings - Fork 249
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 plugin #448
base: master
Are you sure you want to change the base?
Pytest plugin #448
Conversation
It's strange.
but merge decreased total coverage. o.O |
build.py
Outdated
@@ -91,6 +91,7 @@ def initialize(project): | |||
project.build_depends_on("pygments") | |||
if sys.version_info[0:2] == (2, 6): | |||
project.build_depends_on("importlib") # for fluentmock | |||
project.build_depends_on("pytest") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Building PyB does not depend on PyTest. This is supposed to be in pytest plugin as plugin_depends_on
only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed.
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail if pytest
is not installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed (added assert_pytest_avaiable and import moved to inner method)
4 similar comments
Huh... Changes according "use_plugin" usage instead of "build_depends_on" were more deeper than expected, but build is greeen again. |
build.py
Outdated
@@ -38,6 +38,7 @@ | |||
use_plugin("source_distribution") | |||
|
|||
use_plugin("python.unittest") | |||
use_plugin("python.pytest") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I know only two ways to force pybuilder to install any package (in this case - pytest, because pytest_plugin tests use it):
- use build_depends_on('pytest')
- use plugin_depends_on('pytest') and call use_plugin into build.py (otherwise plugin will not be used and pytest will not be installed)
Any other idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're forcing PyBuilder to use pytest for itself here. PyBuilder doesn't use a PyTest unless I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? We test our project by two tools - perfect doublecheck.
On the other hand: if we want to get coverage with pytest we need to call it through import pytest
. So we need installed pytest when we call tests for this plugin. As I understand we can do it by two ways:
- use
build_depends_on('pytest')
use_plugin
+plugin_depends_on('pytest')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, guys.
Do You have any ideas how we can test pytest plugin without usage build_depends_on('pytest')
or use_plugin
+ plugin_depends_on('pytest')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need an integration test for the embedded plugin there are integration tests:
https://github.com/pybuilder/pybuilder/tree/master/src/integrationtest/python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for idea @arcivanov
Moved pytest plugin tests to integration tests.
4 similar comments
4 similar comments
if not _is_module_essential(module.__name__, sys_packages, sys_modules): | ||
try: | ||
# if we try to remove non-module object | ||
module__name__ = module.__name__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a "non-module" object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi.
sys.modules can contains specific objects indead of module. For example, pytest uses AliasModule for this purpose (I see the same behaviour in the couple projects. Unfortunately, I still do not understand reason of it)
print module
<AliasModule 'py.error' for 'py._error.error'>
print type(module)
<class 'py._apipkg.AliasModule'>
In this case module.__name__
will return None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug in PyTest, that violates PEP-0320 and PEP-0420 since Python 3.3. Namely:
https://docs.python.org/3/reference/import.html#import-related-module-attributes
The import machinery fills in these attributes on each module object during loading, based on the module’s spec, before the loader executes the module.
__name__
The __name__ attribute **must be set to the fully-qualified name of the module**. This name is used to uniquely identify the module in the import system.
``` (emphasis added)
Please file a bug with PyTest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is old as mammoth feces and Pytest doesn't use AliasModule anymore. I'll do changes next week and add >=3.2.3
version of Pytest to plugin dependsies.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this problem was fixed, but still isn't released: pytest-dev/py#73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asked about new release pytest-dev/py#153
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm not sure that py
will be releases in the nearest future. I suggest to leave this changes and create new issue revert coverage plugin changes related to py issue
. I'll periodically check py
and do corresponding changes after py
release.
build.py
Outdated
@@ -38,6 +38,7 @@ | |||
use_plugin("source_distribution") | |||
|
|||
use_plugin("python.unittest") | |||
use_plugin("python.pytest") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're forcing PyBuilder to use pytest for itself here. PyBuilder doesn't use a PyTest unless I'm missing something.
4c671f7
to
fe1e8e4
Compare
4 similar comments
pytest tests where moved to integration tests
I still suggest to add |
5d8dfaa
to
8dae883
Compare
8dae883
to
da14970
Compare
da14970
to
fed57de
Compare
fed57de
to
81f55a3
Compare
4 similar comments
81f55a3
to
bbb04d0
Compare
Added |
bbb04d0
to
15f7990
Compare
@arcivanov any news on this, are you happy now? |
Over a month. Marked as useless. Closed. |
Should also affect
And assert_executable |
Workaround for PyTest usage for integration tests. Unfortunately, it's code copy-paste.
|
Integration into core plugins external pytest plugin
https://github.com/AlexeySanko/pybuilder_pytest