#11312 closed defect (fixed)
Tests showing up in Installed Plugins list
Reported by: | Thijs Triemstra | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.2 |
Component: | web frontend | Version: | 1.0-stable |
Severity: | normal | Keywords: | |
Cc: | Thijs Triemstra, Ryan J Ollos | Branch: | |
Release Notes: |
Fixed regression from [12078] that was preventing Pygments from working and caused the test modules to show up in the list of active plugins. |
||
API Changes: | |||
Internal Changes: |
Description (last modified by )
Attachments (1)
Change History (14)
by , 11 years ago
Attachment: | Capture.PNG added |
---|
comment:1 by , 11 years ago
Description: | modified (diff) |
---|
comment:2 by , 11 years ago
Milestone: | → 1.1.2 |
---|
comment:3 by , 11 years ago
Milestone: | 1.1.2 → 1.0.2 |
---|---|
Version: | 1.1.1dev → 1.0-stable |
Reproduced on 1.0-stable branch. Also, I just found non-tests code imports trac.tests.compat
. After the patch, the issue went away in my environment.
-
trac/mimeview/pygments.py
diff --git a/trac/mimeview/pygments.py b/trac/mimeview/pygments.py index 0466577..4286e49 100644
a b from trac.config import ListOption, Option 20 20 from trac.env import ISystemInfoProvider 21 21 from trac.mimeview.api import IHTMLPreviewRenderer, Mimeview 22 22 from trac.prefs import IPreferencePanelProvider 23 from trac.tests import compat24 23 from trac.util import get_pkginfo 25 24 from trac.util.datefmt import http_date, localtz 26 25 from trac.util.translation import _
comment:4 by , 11 years ago
Also noticed that and was confused for a while why Pygments stopped working.
comment:5 by , 11 years ago
That was an error in [12078/branches/1.0-stable/trac/mimeview/pygments.py]. Thanks for spotting it Jun. I'm not sure how I managed to do something so stupid! The import should go in branches/1.0-stable/trac/mimeview/tests/pygments.py because assertIsNone
is used there.
follow-up: 7 comment:6 by , 11 years ago
I see now why I missed this when testing. When a module does not have from trac.tests import compat
, but utilizes a method that is added by the compat
module, in Python 2.5.6 execution of the module will fail. Removing from trac.tests import compat
from trac/web/tests/chrome.py
results in:
PYTHONPATH=. python ./trac/web/tests/href.py ..EEE ====================================================================== ERROR: Build URLs with an empty base. ---------------------------------------------------------------------- Traceback (most recent call last): File "./trac/web/tests/href.py", line 77, in test_empty_base self.assertIn( AttributeError: 'HrefTestCase' object has no attribute 'assertIn'
However, executing the module using the -m
switch, it succeeds even with the missing import:
PYTHONPATH=. python -m trac.web.tests.href SKIP: validation of XHTML output in functional tests (no lxml installed) ..... ---------------------------------------------------------------------- Ran 5 tests in 0.004s OK
As noted in comment:4:ticket:11284, I couldn't get the Pygments module to execute by passing the path, so I had to use the -m
switch.
Any idea why execution using the -m
switch the tests pass even when a required import is missing? It seems like trac.util.compat
is being magically imported somehow.
follow-up: 11 comment:7 by , 11 years ago
As noted in comment:4:ticket:11284, I couldn't get the Pygments module to execute by passing the path, so I had to use the
-m
switch.
If a file is specified in command line, the directory of the file will be added at start of sys.path
. Therefore, pygments
module in site-packages
is hidden on trac.mimeview.tests.pygments
.
When using -m
option, the current directory will be added at start of sys.path
.
Any idea why execution using the
-m
switch the tests pass even when a required import is missing? It seems liketrac.util.compat
is being magically imported somehow.
The -m
option searches sys.path
for the specified module and execute __main__
of the module. The specified module will be imported. Passing the file path, it will not be imported.
As a result, if -m
option, it will load the modules which trac.web.tests.href
depends, e.g. trac
, trac.tests
, etc….
$ git checkout 1.0-stable Switched to branch '1.0-stable' $ PYTHONPATH=. ~/venv/py25/bin/python -v -m trac.web.tests.href -h 2>&1 | egrep 'import trac\.(tests\.compat|web\.tests\.href)' import trac.tests.compat # precompiled from trac/tests/compat.pyc import trac.web.tests.href # from trac/web/tests/href.py $ PYTHONPATH=. ~/venv/py25/bin/python -v trac/web/tests/href.py -h 2>&1 | egrep 'import trac\.(tests\.compat|web\.tests\.href)' import trac.tests.compat # precompiled from /home/jun66j5/src/trac/edgewall/git/trac/tests/compat.pyc
See 1. Command line and environment — Python v2.7.5 documentation.
comment:8 by , 11 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:9 by , 11 years ago
Owner: | set to |
---|
comment:10 by , 11 years ago
Cc: | added |
---|
follow-up: 12 comment:11 by , 11 years ago
Replying to jomae:
As noted in comment:4:ticket:11284, I couldn't get the Pygments module to execute by passing the path, so I had to use the
-m
switch.If a file is specified in command line, the directory of the file will be added at start of
sys.path
. Therefore,pygments
module insite-packages
is hidden ontrac.mimeview.tests.pygments
.When using
-m
option, the current directory will be added at start ofsys.path
.
I can confirm executing with the -v
flag, in which the following is shown:
import pygments # precompiled from /home/user/Workspace/tracdev/teo-rjollos.git/trac/mimeview/tests/pygments.pyc
That makes me consider that it might be better if the Makefile used the -m
flag rather than python $(test) $(testopts). One downside to specifying a module rather than a path is that the Makefile's test=
argument wouldn't be tab-completed on the command line. I also haven't evaluated how testopts
might be affected by the change.
follow-up: 13 comment:12 by , 11 years ago
That makes me consider that it might be better if the Makefile used the
-m
flag rather than python $(test) $(testopts). One downside to specifying a module rather than a path is that the Makefile'stest=
argument wouldn't be tab-completed on the command line. I also haven't evaluated howtestopts
might be affected by the change.
If value of the test
argument doesn't exist as a file, automatically add -m
option. What do you think?
Before the patch, we can explicitly pass -m
option to the test
argument, e.g. make test='-m trac.web.tests.href'
.
-
Makefile
diff --git a/Makefile b/Makefile index d49e3fa..e8ed834 100644
a b export HELP_CFG 126 126 127 127 ifdef test 128 128 all: status 129 python $(test) $(testopts) 129 $(if $(wildcard $(test)), \ 130 python $(test) $(testopts), \ 131 python -m $(test) $(testopts)) 130 132 else 131 133 all: help 132 134 endif … … clean-coverage: 378 380 379 381 ifdef test 380 382 test-coverage: 381 coverage run $(test) $(testopts) 383 $(if $(wildcard $(test)), \ 384 coverage run $(test) $(testopts), \ 385 coverage run -m $(test) $(testopts)) 382 386 else 383 387 test-coverage: unit-test-coverage functional-test-coverage 384 388 endif
comment:13 by , 10 years ago
Replying to jomae:
If value of the
test
argument doesn't exist as a file, automatically add-m
option. What do you think?
That works well. It would be great to push the change.
Places I know of where this behavior could be documented include: TracDev/UnitTests, tags/trac-1.0.1/doc/dev/testing-intro.rst and the help section of Makefile
.
On more than one occasion over the past few weeks I've also noticed these entries showing up as plugins on Plugin Admin panel, but I'm not able to reproduce the issue at the moment.
I've seen two similar cases previously,
However, for this case I think those files should be excluded because of the parameter in
setup.py
:packages = find_packages(exclude=['*.tests']),
.