Ticket #1795 (closed enhancement: fixed )

Opened 3 years ago

Last modified 2 years ago

Trial feature for simulating missing modules for a test run

Reported by: exarkun Assigned to: therve
Type: enhancement Priority: highest
Milestone: Component: trial
Keywords: Cc: therve, jml
Branch: Author:
Launchpad Bug:

Description

It would be nice if trial could fake out Python and make it look like a particular module was not present on the system. ie,

trial --without-module OpenSSL twisted

would run Twisted tests such that "import OpenSSL" always raised an ImportError?.

One implementation technique for this is to put None into sys.modules for the key "OpenSSL".

Attachments

Change History

  2006-06-07 01:54:58+00:00 changed by jml

Sounds cool. Maybe it should be part of a more generic "fake platform problems" feature.

  2007-10-29 17:13:19+00:00 changed by therve

  • owner changed from jml to therve

  2007-10-29 20:09:53+00:00 changed by therve

(In [21495]) KISS

Refs #1795

  2007-10-30 10:53:48+00:00 changed by therve

  • cc set to therve, jml
  • keywords set to review
  • owner deleted
  • priority changed from normal to highest

This is ready to review in without-module-1795. I tried to keep the changes minimal.

follow-up: ↓ 6   2007-11-04 03:34:08+00:00 changed by radix

Here's an idea.

What will happen once I'm using disttrial with ssl connections to my slaves? The current implementation strategy means that it'll break.

On the other hand, I can't think of any way around this at all, apart from making disttrial have separate processes for network I/O layers and actual tests. bleh, whatever.

in reply to: ↑ 5   2007-11-04 10:46:39+00:00 changed by therve

Replying to radix:

On the other hand, I can't think of any way around this at all, apart from making disttrial have separate processes for network I/O layers and actual tests. bleh, whatever.

In fact I think that's the way to do it. Because when you use disttrial, you probably also want that remote hosts use multiple processes. Also, that prevents bad side effects like open sockets and all.

  2007-11-06 14:21:33+00:00 changed by exarkun

  • keywords deleted
  • owner set to therve

test_disableOneModule and test_disableMultipleModules both try to save sys.modules from potential mangling, but they don't actually manage to: savedModules is only a reference to the same dict instance. Make a copy of sys.modules at the beginning and then clear/update sys.modules afterwards (maybe this would be good to do in setUp/tearDown).

The lines like self.assertIdentical(None, checkSmtp()) are a bit weird, since those functions always return None. Maybe they could return what they import and the test could assertNotIdentical? Although I'm mostly saying that so when you add return you can delete the # pyflakes comments which I hate. :)

I wonder if it's worth warning or failing if, in opt_without_module, sys.modules already has a non-None value for the specified key. In this case, the module has been imported already and some code, somewhere (who knows what or where), already has a reference to it, so the environment might not behave exactly as if the module were really absent.

  2007-11-06 16:59:38+00:00 changed by therve

(In [21610]) Fix some tests, add a warning for already imported modules.

Refs #1795

  2007-11-06 17:03:44+00:00 changed by therve

  • keywords set to review
  • owner deleted

I think I fixed everything, back to review!

  2007-11-06 18:01:35+00:00 changed by exarkun

  • keywords deleted
  • owner set to therve

Minor improvement to the man page text:

Simulate the lack of the specified comma-separated list of modules. This makes it look like the modules are not present in the system, causing tests to check the behavior for that configuration.

No other issues, merge when you want.

  2007-11-06 19:22:00+00:00 changed by therve

  • status changed from new to closed
  • resolution set to fixed

(In [21618]) Merge without-module-1795

Author: therve Reviewer: exarkun Fixes #1795

Add the --without-module command line option to trial, that simulates the lack of the specified modules.

Note: See TracTickets for help on using tickets.