Ticket #1795 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

Trial feature for simulating missing modules for a test run

Reported by: exarkun Owned by: therve
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".

Change History

  Changed 4 years ago by jml

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

  Changed 3 years ago by therve

  • owner changed from jml to therve

  Changed 3 years ago by therve

(In [21495]) KISS

Refs #1795

  Changed 3 years ago by therve

  • keywords review added
  • owner therve deleted
  • cc therve, jml added
  • 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   Changed 3 years ago 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   Changed 3 years ago 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.

  Changed 3 years ago by exarkun

  • owner set to therve
  • keywords review removed

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.

  Changed 3 years ago by therve

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

Refs #1795

  Changed 3 years ago by therve

  • owner therve deleted
  • keywords review added

I think I fixed everything, back to review!

  Changed 3 years ago by exarkun

  • keywords review removed
  • 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.

  Changed 3 years ago 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.