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 7925803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:27:55+00:00 2026-06-03T18:27:55+00:00

I just encountered a problem with @unittest.skipIf(expression) . Well, the problem is that if

  • 0

I just encountered a problem with @unittest.skipIf(expression). Well, the problem is that if I use variable in decorator that is declared and assigned a value before starting the test, and during the test the value of this variable is changed the effect is such that decorator includes the old value. For example:

class Settings(object):
    flag=False
class TestCase(object):

    # during the test variable is changed (in this module or another)
    Settings.flag=True

    @unittest.skipIf(Settings.flag==True)
    def test_something(self):
        ...

Value of Settings.flag can be changed in another module or this module (this doesn’t matter). In both cases condition Setting.flag==True during call test_something still takes the ‘False’ value although it was already changed to ‘True’ value. It is very strange and I admit that I don’t understand how this mechanism works. It seems that the value used in this decorator can’t be changed during the test. Maybe there is some other interesting way to skip the test at the time of a particular condition, which may change during the test. Does anyone have an idea how to approach this problem?

  • 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-03T18:27:56+00:00Added an answer on June 3, 2026 at 6:27 pm

    Yes, this is expected behavior. Function arguments are evaluated when the function is called. The decorator is a function that’s called when the function being decorated is defined. Therefore, the flag is tested when the decorated function is defined. The decorator has no way to know what the test even was; it only sees True or False (or more likely, truthiness or falsiness) so it can’t store the condition away for later evaluation.

    For skipIf() to work as you want, it would need to take a function (e.g. lambda: Settings.flag==True) rather than a Boolean value. Then it would be able to evaluate this condition later, when the decorated function is actually called. But it doesn’t actually work that way. (This would probably be an easy enhancement to add, though.)

    You may be able to work around this by not importing the module containing your unit tests until after the value of Settings.flag has been established. This will defer the definition (and thus the decoration) of your test functions until then, and the decorator will have access to the desired value of the flag. Not knowing how your code is structured, I don’t know whether this is practical for you.

    Additionally, something looks fishy about Settings.flag==True… can’t quite put my finger on it… 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just encountered a problem that my current (almost equal to 0) CSS knowledge
I've just encountered a rather strange problem. A Winforms (although that may not be
I have encountered a problem that I have never seen before. Usually, when I
I just encountered with a problem that I don't know how to solve. It
I've just encountered a weird problem, I'm trying to printf an integer variable, but
I've just encountered an interesting problem related to Java generics. I'd like to use
Hi I am a C++ beginner just encountered a problem I don't know how
I've just started using HTTParty, and i've encountered a problem in the way it
I just encountered a weird error which saying that find is not a member
I have just encountered very strange problem - my GWT app hosted on Google

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.