question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot change class members value after final assert statements

See original GitHub issue

Given I have a test class with two or more test functions, and the class has class members who are assigned static strings from a config file, When I reassign one of the class members value after the assert statement in the first test function (regardless whether this is the first function in the test or one before last), Then in the following test the class member remains with the value that was assigned to it, prior to the change.

pytest 3.6.1

class MyTest():
    a = "dog"
    b = "cat"
    
    def test_one(self):
        assert 1 + 1 == 2
        self.a = self.b

    def test_two(self):
        # here self.a is equal to "dog" instead of "cat"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
RonnyPfannschmidtcommented, Aug 11, 2019

each test gets a new instance, as far as pytest is concerned this is a feature

0reactions
MosheSheenacommented, Aug 13, 2019

Thank you @LaurentMarchelli for this clear example! I will certainly adopt this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to declare a method that cannot change the class ...
A final field or variable is a constant. Its value cannot be changed once assigned. A final method cannot be overridden by child...
Read more >
Programming With Assertions - Oracle Help Center
An assertion is a statement in the Java TM programming language that enables you to test your assumptions about your program. For example,...
Read more >
Subclassing and Inheritance - Learning Java, 4th Edition [Book]
Subclassing and Inheritance Classes in Java exist in a hierarchy. A class in Java can be declared as a subclass of another class...
Read more >
More Assertions
When a test assertion such as EXPECT_EQ fails, Google Test prints the argument values to help you debug. It does this using a...
Read more >
Python's assert: Debug and Test Your Code Like a Pro
In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found