Skip to content
This repository was archived by the owner on Jul 9, 2020. It is now read-only.
This repository was archived by the owner on Jul 9, 2020. It is now read-only.

Current Working Directory Warning Issues #95

@rallytime

Description

@rallytime

The changes made in PR #93 are causing two test classes in a full jenkins test run to display the WARNING message that the pull request added about the misbehaving test/changing working directory.

However, it became apparent that this message displays at the beginning of every test run - which ever test class was the first class to run, then the WARNING will be triggered for the class.

I made the following edits to salttesting.unit.py to display what the current working directory is at various points of the tearDown process:

diff --git a/salttesting/unit.py b/salttesting/unit.py
index f082cfe..74b5db4 100644
--- a/salttesting/unit.py
+++ b/salttesting/unit.py
@@ -104,11 +104,17 @@ class TestCase(_TestCase):

         This hard-resets the environment between test classes
         '''
+        print('cls._cwd() = {0}'.format(cls._cwd))
+        print('os.get_cwd() = {0}'.format(os.getcwd()))
         # Compare where we are now compared to where we were when we began this family of tests
         if not cls._cwd == os.getcwd():
             os.chdir(cls._cwd)
             print('\nWARNING: A misbehaving test has modified the working directory!\nThe test suite has reset the working direct
                     'on tearDown() to {0}\n'.format(cls._cwd))
+        print('after warning')
+        print('os.get_cwd() = {0}'.format(os.getcwd()))
         super(TestCase, cls).tearDownClass()

Then, I ran a simple unit test like so: python2 runtests.py -n unit.spm_test which printed the following results:

.cls._cwd() = /root/SaltStack/salt/tests
os.get_cwd() = /root/SaltStack/salt

WARNING: A misbehaving test has modified the working directory!
The test suite has reset the working directory on tearDown() to /root/SaltStack/salt/tests

after warning
os.get_cwd() = /root/SaltStack/salt/tests
.cls._cwd() = /root/SaltStack/salt/tests
os.get_cwd() = /root/SaltStack/salt/tests
after warning
os.get_cwd() = /root/SaltStack/salt/tests

You can see that the call to os.getcwd() on this line of the change has a different working directory than what is present for the initial os.getcwd() call at the top of the TestCase class definition.

NOTE: We run an os.getcwd() call right at the beginning of the test run when we print some information about the test logger and the test PID, etc, which looks like this:

 * Transplanting configuration files to '/tmp/salt-tests-tmpdir/config'
 * Current Directory: /root/SaltStack/salt
 * Test suite is running under PID 32730
 * Logging tests on /tmp/salt-runtests.log

See that the Current Directory matches the os.getcwd() call in the overridden tearDown class.

I haven't been able to track down why this call to os.getcwd() is returning a different directory than one with the /tests extension.

@cachedout What do you think about this assessment?

This issue replaces saltstack/salt#36415 and saltstack/salt#36416

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions