Edgewall Software
Modify

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#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:

Description (last modified by Thijs Triemstra)

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

Attachments (1)

Capture.PNG (18.2 KB ) - added by Thijs Triemstra 6 years ago.

Download all attachments as: .zip

Change History (14)

by Thijs Triemstra, 6 years ago

Attachment: Capture.PNG added

comment:1 by Thijs Triemstra, 6 years ago

Description: modified (diff)

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

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

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

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

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

comment:9 by Ryan J Ollos, 6 years ago

Owner: set to Jun Omae

comment:10 by Ryan J Ollos, 6 years ago

Cc: Ryan J Ollos added

in reply to:  7 ; comment:11 by Ryan J Ollos, 5 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 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.

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.

in reply to:  11 ; comment:12 by Jun Omae, 5 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'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.

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  
    126126
    127127ifdef test
    128128all: status
    129        python $(test) $(testopts)
     129       $(if $(wildcard $(test)), \
     130           python $(test) $(testopts), \
     131           python -m $(test) $(testopts))
    130132else
    131133all: help
    132134endif
    clean-coverage:  
    378380
    379381ifdef test
    380382test-coverage:
    381        coverage run $(test) $(testopts)
     383       $(if $(wildcard $(test)), \
     384           coverage run $(test) $(testopts), \
     385           coverage run -m $(test) $(testopts))
    382386else
    383387test-coverage: unit-test-coverage functional-test-coverage
    384388endif

in reply to:  12 comment:13 by Ryan J Ollos, 5 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.

Please 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.

Version 1, edited 5 years ago by Ryan J Ollos (previous) (next) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.