Cannot change class members value after final assert statements
See original GitHub issueGiven 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:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
each test gets a new instance, as far as pytest is concerned this is a feature
Thank you @LaurentMarchelli for this clear example! I will certainly adopt this.