Edgewall Software

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#11312 closed defect (fixed)

Tests showing up in Installed Plugins list — at Version 8

Reported by: Thijs Triemstra Owned by:
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 Thijs Triemstra)

The about page shows trac test-related plugins being installed. Can these be omitted?

Change History (9)

by Thijs Triemstra, 11 years ago

Attachment: Capture.PNG added

comment:1 by Thijs Triemstra, 11 years ago

Description: modified (diff)

comment:2 by Ryan J Ollos, 11 years ago

Milestone: 1.1.2

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']),.

comment:3 by Jun Omae, 11 years ago

Milestone: 1.1.21.0.2
Version: 1.1.1dev1.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  
    2020from trac.env import ISystemInfoProvider
    2121from trac.mimeview.api import IHTMLPreviewRenderer, Mimeview
    2222from trac.prefs import IPreferencePanelProvider
    23 from trac.tests import compat
    2423from trac.util import get_pkginfo
    2524from trac.util.datefmt import http_date, localtz
    2625from trac.util.translation import _

comment:4 by Thijs Triemstra, 11 years ago

Also noticed that and was confused for a while why Pygments stopped working.

comment:5 by Ryan J Ollos, 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.

comment:6 by Ryan J Ollos, 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.

in reply to:  6 comment:7 by Jun Omae, 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 like trac.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 Ryan J Ollos, 11 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Fixed on 1.0-stable in [12115] and merged to trunk in [12116].

Note: See TracTickets for help on using tickets.