Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:41:34+00:00 2026-06-13T00:41:34+00:00

I’ve inherited some python code that writes a new ‘/etc/udev/rules.d’ mapping file and then

  • 0

I’ve inherited some python code that writes a new ‘/etc/udev/rules.d’ mapping file and then makes a subprocess call to udev to have it refresh its devices list:

call(['/sbin/udevadm', 'trigger', '--action=change'])

The trigger call is necessary as we need the mapping to update without wanting to unplug and plug back in the device being mapped. My problem is the ‘call’ line was removed at one point, causing non-obvious side-effects in other parts of the program and so was not caught.

My usual way of fixing something like this is to throw a unit-test on this method (which writes the mapping file and calls trigger) to enforce the expected behaviour, but this behaviour seems outside of the realm of unit-testing. It’s a system call, not to mention udevadm trigger requires sudo access. I can’t figure out how/what to mock out in this instance.

I considered using the pyudev library as I saw that it can mock certain behaviour of udev, but it doesn’t look like it can mock the trigger behaviour (or even access it for that matter).

Short of throwing a big “#DO NOT DELETE THIS LINE EVER!” above the “call” line, is there anything I can do here to prevent this from being removed in the future? “DO NOT DELETE” lines are easily ignored say a year from now when no one has a clue why it’s there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:41:35+00:00Added an answer on June 13, 2026 at 12:41 am

    Here’s what I decided to do in this instance, if anyone disagrees with my answer please chime in!

    It’s a two parter.

    First I wrapped the call I was concerned about and switched the straight ‘call’ to this in my code.

    class UdevWrapper:
        def udevadm_trigger(self):
            call(['/sbin/udevadm', 'trigger', '--action=change'])
    

    (The class contains more than this, just simplified here for clarity)

    Next I mocked out the wrapper method and tested to ensure that it was called

    @patch.object(utils.UdevWrapper,'udevadm_trigger')
    def test_trigger_called(self,mock_udevadm_trigger):
        mock_udevadm_trigger.return_value = True
    
        # name changed for clarity
        ClassWhereTriggerCalled.func()
        assert mock_udevadm_trigger.called
    

    Doing it this way was inspired by reading about Behaviour Driven Development. The whole idea of BDD is brand new to me so I’m not sure stylistically/functionally how BDD proponents will feel about my solution but it does what I wanted – something obviously breaks (my test) if this line of code is removed in the future.

    I plan on switching it to use monkeypatch in the future so that I can create a stub function that can check state (the order in which trigger is called is also important). However the principle remains the same:

    1. Wrap in a method that can be mocked
    2. Write test to ensure correct functional behaviour
    3. Mock wrapped method
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.